file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.lemma_b_pow2_256_plus_a_modq_lseq | val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q) | val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q) | let lemma_b_pow2_256_plus_a_modq_lseq len a =
lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4 | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 348,
"start_col": 0,
"start_line": 346
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q)
let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
}
val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Lib.IntTypes.size_nat{4 <= len} -> a: Lib.Sequence.lseq Lib.IntTypes.uint64 len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v a % Spec.K256.PointOps.q ==
(Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub a 4 (len - 4)) *
(Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub a 0 4)) %
Spec.K256.PointOps.q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.U64",
"Prims.unit",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_b_pow2_256_plus_a_modq",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Sequence.sub",
"Prims.op_Subtraction"
] | [] | true | false | true | false | false | let lemma_b_pow2_256_plus_a_modq_lseq len a =
| lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4 | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mod_short_lseq_lemma | val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q) | val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q) | let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 157,
"start_col": 0,
"start_line": 148
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.K256.Scalar.qelem_lseq
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.K256.Scalar.mod_short_lseq a) ==
Hacl.Spec.Bignum.Definitions.bn_v a % Spec.K256.PointOps.q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.K256.Scalar.qelem_lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.K256.Scalar.Lemmas.mod_short_lseq_lemma_aux",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.K256.PointOps.q",
"Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_is_qas_nat",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.Sequence.create4",
"Hacl.Spec.K256.Scalar.qelem4",
"Hacl.Spec.K256.Scalar.make_pow2_256_minus_order_k256"
] | [] | false | false | true | false | false | let mod_short_lseq_lemma a =
| let t0, t1, t2, t3 = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.lemma_pow_mod_is_pow_cm | val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b) | val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b) | let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 17,
"start_col": 0,
"start_line": 15
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.Curve25519.elem -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Curve25519.Finv.pow x b =
Lib.Exponentiation.Definition.pow Hacl.Spec.Curve25519.Finv.cm_prime x b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Curve25519.elem",
"Prims.nat",
"Lib.NatMod.lemma_pow_mod",
"Spec.Curve25519.prime",
"Prims.unit",
"Lib.NatMod.lemma_pow_nat_mod_is_pow"
] | [] | true | false | true | false | false | let lemma_pow_mod_is_pow_cm x b =
| M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b | false |
Target.fsti | Target.mk_subst | val mk_subst (l: list param) (args: list expr) : ML (option subst) | val mk_subst (l: list param) (args: list expr) : ML (option subst) | let mk_subst (l:list param) (args:list expr) : ML (option subst) =
if List.Tot.length l <> List.Tot.length args
then None
else (
Some (List.map2 #param (fun (i, t) e -> i.v, e) l args)
) | {
"file_name": "src/3d/Target.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 119,
"start_col": 0,
"start_line": 114
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Target
(* The abstract syntax for the code produced by 3d *)
open FStar.All
module A = Ast
open Binding
/// The same as A.op, but with `SizeOf` removed
/// and arithmetic operators resolved to their types
type op =
| Eq
| Neq
| And
| Or
| Not
| Plus of A.integer_type
| Minus of A.integer_type
| Mul of A.integer_type
| Division of A.integer_type
| Remainder of A.integer_type
| BitwiseAnd of A.integer_type
| BitwiseXor of A.integer_type
| BitwiseOr of A.integer_type
| BitwiseNot of A.integer_type
| ShiftRight of A.integer_type
| ShiftLeft of A.integer_type
| LT of A.integer_type
| GT of A.integer_type
| LE of A.integer_type
| GE of A.integer_type
| IfThenElse
| BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to)
| Cast : from:A.integer_type -> to:A.integer_type -> op
| Ext of string
/// Same as A.expr, but with `This` removed
///
/// Carrying around the range information from AST.expr so that we
/// can report errors in terms of their 3d file locations
noeq
type expr' =
| Constant : c:A.constant -> expr'
| Identifier : i:A.ident -> expr'
| App : hd:op -> args:list expr -> expr'
| Record : type_name:A.ident -> list (A.ident * expr) -> expr'
and expr = expr' & A.range
let subst = list (A.ident' & expr)
val subst_expr (s:subst) (e:expr) : expr
let mk_expr (e:expr') = e, A.dummy_range
type lam a = (option A.ident) & a
noeq
type atomic_action =
| Action_return of expr
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr
| Action_field_ptr_after: sz: expr -> write_to:A.ident -> atomic_action
| Action_field_ptr_after_with_setter: sz: expr -> write_to_field:A.ident -> write_to_object:expr -> atomic_action
| Action_deref of A.ident
| Action_assignment : lhs:A.ident -> rhs:expr -> atomic_action
| Action_call : f:A.ident -> args:list expr -> atomic_action
noeq
type action =
| Atomic_action of atomic_action
| Action_seq : hd:atomic_action -> tl:action -> action
| Action_ite : hd:expr -> then_:action -> else_:action -> action
| Action_let : i:A.ident -> a:atomic_action -> k:action -> action
| Action_act : action -> action
(* A subset of F* types that the translation targets *)
noeq
type typ =
| T_false : typ
| T_app : hd:A.ident -> A.t_kind -> args:list index -> typ
| T_dep_pair : dfst:typ -> dsnd:(A.ident & typ) -> typ
| T_refine : base:typ -> refinement:lam expr -> typ
| T_if_else : e:expr -> t:typ -> f:typ -> typ
| T_pointer : typ -> typ
| T_with_action: typ -> action -> typ
| T_with_dep_action: typ -> a:lam action -> typ
| T_with_comment: typ -> A.comments -> typ
| T_with_probe: typ -> probe_fn:A.ident -> len:expr -> dest:A.ident -> typ
(* An index is an F* type or an expression
-- we reuse Ast expressions for this
*)
and index = either typ expr
let field_typ = typ
type param = A.ident & typ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Target.fsti"
} | [
{
"abbrev": false,
"full_module": "Binding",
"short_module": null
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Binding",
"short_module": null
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list Target.param -> args: Prims.list Target.expr
-> FStar.All.ML (FStar.Pervasives.Native.option Target.subst) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.list",
"Target.param",
"Target.expr",
"Prims.op_disEquality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Pervasives.Native.None",
"Target.subst",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"FStar.List.map2",
"FStar.Pervasives.Native.tuple2",
"Ast.ident'",
"Ast.ident",
"Target.typ",
"FStar.Pervasives.Native.Mktuple2",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [] | false | true | false | false | false | let mk_subst (l: list param) (args: list expr) : ML (option subst) =
| if List.Tot.length l <> List.Tot.length args
then None
else (Some (List.map2 #param (fun (i, t) e -> i.v, e) l args)) | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.lemma_pow_double | val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b)) | val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b)) | let lemma_pow_double a b =
lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b) | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 45,
"start_col": 0,
"start_line": 42
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m))
let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m)
val lemma_pow_double: a:elem -> b:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Curve25519.elem -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures Hacl.Spec.Curve25519.Finv.pow (a *% a) b == Hacl.Spec.Curve25519.Finv.pow a (b + b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Curve25519.elem",
"Prims.nat",
"Hacl.Spec.Curve25519.Finv.lemma_pow_mod_is_pow_cm",
"Prims.op_Addition",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_double",
"Lib.NatMod.nat_mod",
"Spec.Curve25519.prime",
"Hacl.Spec.Curve25519.Finv.cm_prime",
"Spec.Curve25519.op_Star_Percent"
] | [] | true | false | true | false | false | let lemma_pow_double a b =
| lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_add_lemma | val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 241,
"start_col": 0,
"start_line": 223
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
resLen: Lib.IntTypes.size_nat{2 + len <= resLen /\ 4 <= resLen} ->
d: Prims.nat ->
a: Lib.Sequence.lseq Lib.IntTypes.uint64 len ->
e: Lib.Sequence.lseq Lib.IntTypes.uint64 4
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Bignum.Definitions.bn_v a < Prims.pow2 d /\ d + 129 < 64 * resLen)
(ensures
(let _ = Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add len resLen a e in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (64 * resLen) + Hacl.Spec.Bignum.Definitions.bn_v res =
Hacl.Spec.Bignum.Definitions.bn_v a * (Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v e /\
Hacl.Spec.Bignum.Definitions.bn_v a * (Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v e <
Prims.pow2 (d + 129) + Prims.pow2 256)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.nat",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.K256.PointOps.q",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Prims.op_Equality",
"Hacl.Spec.K256.Scalar.Lemmas.carry_is_zero",
"FStar.Math.Lemmas.pow2_lt_compat",
"Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_lt_lemma",
"Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_lemma",
"Lib.IntTypes.int_t",
"Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq"
] | [] | false | false | true | false | false | let mul_pow2_256_minus_q_add_lemma len resLen d a e =
| let c0, m = mul_pow2_256_minus_q_lseq len resLen a in
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256) | false |
Pulse.Typing.fst | Pulse.Typing.tm_int | val tm_int : Pulse.Syntax.Base.term | let tm_int = tm_fvar (as_fv int_lid) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 36,
"start_col": 0,
"start_line": 36
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.int_lid"
] | [] | false | false | false | true | false | let tm_int =
| tm_fvar (as_fv int_lid) | false |
|
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.lemma_pow_one | val lemma_pow_one: x:elem -> Lemma (x == pow x 1) | val lemma_pow_one: x:elem -> Lemma (x == pow x 1) | let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 22,
"start_col": 0,
"start_line": 20
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.Curve25519.elem -> FStar.Pervasives.Lemma (ensures x == Hacl.Spec.Curve25519.Finv.pow x 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Curve25519.elem",
"Lib.Exponentiation.Definition.lemma_pow1",
"Lib.NatMod.nat_mod",
"Spec.Curve25519.prime",
"Hacl.Spec.Curve25519.Finv.cm_prime",
"Prims.unit",
"Hacl.Spec.Curve25519.Finv.lemma_pow_mod_is_pow_cm"
] | [] | true | false | true | false | false | let lemma_pow_one x =
| lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_lemma | val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q)) | val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q)) | let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q)) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 193,
"start_col": 0,
"start_line": 164
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
resLen: Lib.IntTypes.size_nat{2 + len <= resLen} ->
a: Lib.Sequence.lseq Lib.IntTypes.uint64 len
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq len resLen a in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (64 * resLen) + Hacl.Spec.Bignum.Definitions.bn_v res =
Hacl.Spec.Bignum.Definitions.bn_v a * (Prims.pow2 256 - Spec.K256.PointOps.q))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Subtraction",
"Spec.K256.PointOps.q",
"Prims.unit",
"FStar.Math.Lemmas.distributivity_add_right",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Hacl.Spec.Bignum.Definitions.bn_eval_zeroes",
"Lib.Sequence.eq_intro",
"Lib.Sequence.sub",
"Lib.Sequence.create",
"Lib.IntTypes.u64",
"Hacl.Spec.Bignum.Definitions.bn_update_sub_eval",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_imp",
"Hacl.Spec.Bignum.bn_mul_lemma",
"Hacl.Spec.Bignum.bn_mul",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.Sequence.create2",
"FStar.Pervasives.assert_norm",
"Lib.IntTypes.range"
] | [] | false | false | true | false | false | let mul_pow2_256_minus_q_lemma len resLen a =
| let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q)) | false |
Pulse.Typing.fst | Pulse.Typing.debug_log | val debug_log (level: string) (g: env) (f: (unit -> T.Tac string)) : T.Tac unit | val debug_log (level: string) (g: env) (f: (unit -> T.Tac string)) : T.Tac unit | let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 32,
"start_col": 0,
"start_line": 30
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
level: Prims.string ->
g: Pulse.Typing.Env.env ->
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.string)
-> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"Pulse.Typing.Env.env",
"Prims.unit",
"Pulse.RuntimeUtils.debug_at_level",
"Pulse.Typing.Env.fstar_env",
"FStar.Stubs.Tactics.V2.Builtins.print",
"FStar.Printf.sprintf",
"Prims.bool"
] | [] | false | true | false | false | false | let debug_log (level: string) (g: env) (f: (unit -> T.Tac string)) : T.Tac unit =
| if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | false |
Pulse.Typing.fst | Pulse.Typing.tm_nat | val tm_nat : Pulse.Syntax.Base.term | let tm_nat = tm_fvar (as_fv nat_lid) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 37,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.nat_lid"
] | [] | false | false | false | true | false | let tm_nat =
| tm_fvar (as_fv nat_lid) | false |
|
Pulse.Typing.fst | Pulse.Typing.tm_true | val tm_true : Pulse.Syntax.Base.term | let tm_true = tm_constant R.C_True | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_constant",
"FStar.Stubs.Reflection.V2.Data.C_True"
] | [] | false | false | false | true | false | let tm_true =
| tm_constant R.C_True | false |
|
Pulse.Typing.fst | Pulse.Typing.mk_erased | val mk_erased (u: universe) (t: term) : term | val mk_erased (u: universe) (t: term) : term | let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 46,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u10: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.erased_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_erased (u: universe) (t: term) : term =
| let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t | false |
Pulse.Typing.fst | Pulse.Typing.mk_hide | val mk_hide (u: universe) (t e: term) : term | val mk_hide (u: universe) (t e: term) : term | let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 56,
"start_col": 0,
"start_line": 53
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u22: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.hide_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_hide (u: universe) (t e: term) : term =
| let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | false |
Pulse.Typing.fst | Pulse.Typing.mk_reveal | val mk_reveal (u: universe) (t e: term) : term | val mk_reveal (u: universe) (t e: term) : term | let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 51,
"start_col": 0,
"start_line": 48
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u16: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.reveal_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_reveal (u: universe) (t e: term) : term =
| let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | false |
Pulse.Typing.fst | Pulse.Typing.tm_unit | val tm_unit : Pulse.Syntax.Base.term | let tm_unit = tm_fvar (as_fv unit_lid) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 34,
"start_col": 0,
"start_line": 34
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.unit_lid"
] | [] | false | false | false | true | false | let tm_unit =
| tm_fvar (as_fv unit_lid) | false |
|
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.lemma_m_bound | val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130) | val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130) | let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 280,
"start_col": 0,
"start_line": 273
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Lib.Sequence.lseq Lib.IntTypes.uint64 7
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Bignum.Definitions.bn_v m < Prims.pow2 385 + Prims.pow2 256)
(ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub m 4 3) < Prims.pow2 130) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Lib.Sequence.sub",
"Prims.pow2",
"Prims.unit",
"FStar.Math.Lemmas.lemma_div_lt",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"FStar.Math.Lemmas.pow2_double_sum",
"FStar.Math.Lemmas.pow2_lt_compat"
] | [] | true | false | true | false | false | let lemma_m_bound m =
| Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130) | false |
Pulse.Typing.fst | Pulse.Typing.tm_bool | val tm_bool : Pulse.Syntax.Base.term | let tm_bool = tm_fvar (as_fv bool_lid) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.bool_lid"
] | [] | false | false | false | true | false | let tm_bool =
| tm_fvar (as_fv bool_lid) | false |
|
Pulse.Typing.fst | Pulse.Typing.tm_false | val tm_false : Pulse.Syntax.Base.term | let tm_false = tm_constant R.C_False | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 40,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_constant",
"FStar.Stubs.Reflection.V2.Data.C_False"
] | [] | false | false | false | true | false | let tm_false =
| tm_constant R.C_False | false |
|
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.lemma_pow_add | val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m)) | val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m)) | let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m) | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 30,
"start_col": 0,
"start_line": 26
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.Curve25519.elem -> n: Prims.nat -> m: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Spec.Curve25519.fmul (Hacl.Spec.Curve25519.Finv.pow x n) (Hacl.Spec.Curve25519.Finv.pow x m) ==
Hacl.Spec.Curve25519.Finv.pow x (n + m)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Curve25519.elem",
"Prims.nat",
"Hacl.Spec.Curve25519.Finv.lemma_pow_mod_is_pow_cm",
"Prims.op_Addition",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_add",
"Lib.NatMod.nat_mod",
"Spec.Curve25519.prime",
"Hacl.Spec.Curve25519.Finv.cm_prime"
] | [] | true | false | true | false | false | let lemma_pow_add x n m =
| lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.lemma_p_bound | val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4) | val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4) | let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 294,
"start_col": 0,
"start_line": 287
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Lib.Sequence.lseq Lib.IntTypes.uint64 5
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Bignum.Definitions.bn_v p < Prims.pow2 259 + Prims.pow2 256)
(ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub p 4 1) < Prims.pow2 4) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Lib.Sequence.sub",
"Prims.pow2",
"Prims.unit",
"FStar.Math.Lemmas.lemma_div_lt",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"FStar.Math.Lemmas.pow2_double_sum",
"FStar.Math.Lemmas.pow2_lt_compat"
] | [] | true | false | true | false | false | let lemma_p_bound p =
| Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4) | false |
Pulse.Typing.fst | Pulse.Typing.tm_szt | val tm_szt : Pulse.Syntax.Base.term | let tm_szt = tm_fvar (as_fv szt_lid) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.szt_lid"
] | [] | false | false | false | true | false | let tm_szt =
| tm_fvar (as_fv szt_lid) | false |
|
Pulse.Typing.fst | Pulse.Typing.mk_vprop_eq | val mk_vprop_eq (e0 e1: term) : term | val mk_vprop_eq (e0 e1: term) : term | let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 74,
"start_col": 0,
"start_line": 73
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e0: Pulse.Syntax.Base.term -> e1: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Typing.mk_eq2",
"Pulse.Syntax.Pure.u2",
"Pulse.Syntax.Base.tm_vprop"
] | [] | false | false | false | true | false | let mk_vprop_eq (e0 e1: term) : term =
| mk_eq2 u2 tm_vprop e0 e1 | false |
Pulse.Typing.fst | Pulse.Typing.mk_eq2 | val mk_eq2 (u: universe) (t e0 e1: term) : term | val mk_eq2 (u: universe) (t e0 e1: term) : term | let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 64,
"start_col": 0,
"start_line": 58
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u30: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
e0: Pulse.Syntax.Base.term ->
e1: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"FStar.Reflection.Const.eq2_qn",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.Implicit",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let mk_eq2 (u: universe) (t e0 e1: term) : term =
| tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0)
None
e1 | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.fsquare_times | val fsquare_times: inp:elem -> n:pos -> out:elem{out == pow inp (pow2 n)} | val fsquare_times: inp:elem -> n:pos -> out:elem{out == pow inp (pow2 n)} | let fsquare_times inp n =
let out = fsqr inp in
lemma_pow_one inp;
lemma_pow_add inp 1 1;
assert_norm (pow2 1 = 2);
assert (out == pow inp (pow2 1));
let out =
Lib.LoopCombinators.repeati_inductive #elem (n - 1)
(fun i out -> out == pow inp (pow2 (i + 1)))
(fun i out ->
assert (out == pow inp (pow2 (i + 1)));
let res = fsqr out in
calc (==) {
fmul out out;
(==) { lemma_pow_add inp (pow2 (i + 1)) (pow2 (i + 1)) }
pow inp (pow2 (i + 1) + pow2 (i + 1));
(==) { Math.Lemmas.pow2_double_sum (i + 1) }
pow inp (pow2 (i + 2));
};
res) out in
assert (out == pow inp (pow2 n));
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 70,
"start_col": 0,
"start_line": 49
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m))
let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m)
val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b))
let lemma_pow_double a b =
lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inp: Spec.Curve25519.elem -> n: Prims.pos
-> out: Spec.Curve25519.elem{out == Hacl.Spec.Curve25519.Finv.pow inp (Prims.pow2 n)} | Prims.Tot | [
"total"
] | [] | [
"Spec.Curve25519.elem",
"Prims.pos",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Curve25519.Finv.pow",
"Prims.pow2",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Lib.LoopCombinators.repeati_inductive",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Calc.calc_finish",
"Spec.Curve25519.fmul",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Curve25519.Finv.lemma_pow_add",
"Prims.squash",
"FStar.Math.Lemmas.pow2_double_sum",
"Hacl.Spec.Curve25519.Finv.fsqr",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Curve25519.Finv.lemma_pow_one"
] | [] | false | false | false | false | false | let fsquare_times inp n =
| let out = fsqr inp in
lemma_pow_one inp;
lemma_pow_add inp 1 1;
assert_norm (pow2 1 = 2);
assert (out == pow inp (pow2 1));
let out =
Lib.LoopCombinators.repeati_inductive #elem
(n - 1)
(fun i out -> out == pow inp (pow2 (i + 1)))
(fun i out ->
assert (out == pow inp (pow2 (i + 1)));
let res = fsqr out in
calc ( == ) {
fmul out out;
( == ) { lemma_pow_add inp (pow2 (i + 1)) (pow2 (i + 1)) }
pow inp (pow2 (i + 1) + pow2 (i + 1));
( == ) { Math.Lemmas.pow2_double_sum (i + 1) }
pow inp (pow2 (i + 2));
};
res)
out
in
assert (out == pow inp (pow2 n));
out | false |
Pulse.Typing.fst | Pulse.Typing.elab_env | val elab_env (e: env) : R.env | val elab_env (e: env) : R.env | let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 114,
"start_col": 0,
"start_line": 114
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Typing.Env.env -> FStar.Stubs.Reflection.Types.env | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.extend_env_l",
"Pulse.Typing.Env.fstar_env",
"Pulse.Typing.Env.bindings",
"FStar.Stubs.Reflection.Types.env"
] | [] | false | false | false | true | false | let elab_env (e: env) : R.env =
| extend_env_l (fstar_env e) (bindings e) | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.lemma_pow_mul | val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m)) | val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m)) | let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m) | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 38,
"start_col": 0,
"start_line": 34
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.Curve25519.elem -> n: Prims.nat -> m: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Curve25519.Finv.pow (Hacl.Spec.Curve25519.Finv.pow x n) m ==
Hacl.Spec.Curve25519.Finv.pow x (n * m)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Curve25519.elem",
"Prims.nat",
"Hacl.Spec.Curve25519.Finv.lemma_pow_mod_is_pow_cm",
"FStar.Mul.op_Star",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_mul",
"Lib.NatMod.nat_mod",
"Spec.Curve25519.prime",
"Hacl.Spec.Curve25519.Finv.cm_prime",
"Hacl.Spec.Curve25519.Finv.pow"
] | [] | true | false | true | false | false | let lemma_pow_mul x n m =
| lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m) | false |
Pulse.Typing.fst | Pulse.Typing.mk_pts_to | val mk_pts_to (ty r v: term) : term | val mk_pts_to (ty r v: term) : term | let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 83,
"start_col": 0,
"start_line": 78
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ty: Pulse.Syntax.Base.term -> r: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.full_perm_lid",
"Pulse.Reflection.Util.pts_to_lid"
] | [] | false | false | false | true | false | let mk_pts_to (ty r v: term) : term =
| let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | false |
Pulse.Typing.fst | Pulse.Typing.mk_sq_eq2 | val mk_sq_eq2 (u: universe) (t e0 e1: term) : term | val mk_sq_eq2 (u: universe) (t e0 e1: term) : term | let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 71,
"start_col": 0,
"start_line": 66
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u38: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
e0: Pulse.Syntax.Base.term ->
e1: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"FStar.Reflection.Const.squash_qn",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Typing.mk_eq2"
] | [] | false | false | false | true | false | let mk_sq_eq2 (u: universe) (t e0 e1: term) : term =
| let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.pow_t0 | val pow_t0:nat | val pow_t0:nat | let pow_t0:nat =
assert_norm (pow2 255 - pow2 5 > 0);
pow2 255 - pow2 5 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 74,
"start_col": 0,
"start_line": 72
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m))
let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m)
val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b))
let lemma_pow_double a b =
lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b)
val fsquare_times: inp:elem -> n:pos -> out:elem{out == pow inp (pow2 n)}
let fsquare_times inp n =
let out = fsqr inp in
lemma_pow_one inp;
lemma_pow_add inp 1 1;
assert_norm (pow2 1 = 2);
assert (out == pow inp (pow2 1));
let out =
Lib.LoopCombinators.repeati_inductive #elem (n - 1)
(fun i out -> out == pow inp (pow2 (i + 1)))
(fun i out ->
assert (out == pow inp (pow2 (i + 1)));
let res = fsqr out in
calc (==) {
fmul out out;
(==) { lemma_pow_add inp (pow2 (i + 1)) (pow2 (i + 1)) }
pow inp (pow2 (i + 1) + pow2 (i + 1));
(==) { Math.Lemmas.pow2_double_sum (i + 1) }
pow inp (pow2 (i + 2));
};
res) out in
assert (out == pow inp (pow2 n));
out | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_GreaterThan"
] | [] | false | false | false | true | false | let pow_t0:nat =
| assert_norm (pow2 255 - pow2 5 > 0);
pow2 255 - pow2 5 | false |
Pulse.Typing.fst | Pulse.Typing.freshv | val freshv (g: env) (x: var) : prop | val freshv (g: env) (x: var) : prop | let freshv (g:env) (x:var) : prop =
None? (lookup g x) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 123,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> x: Pulse.Syntax.Base.var -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.var",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.Env.lookup",
"Prims.prop"
] | [] | false | false | false | true | true | let freshv (g: env) (x: var) : prop =
| None? (lookup g x) | false |
Pulse.Typing.fst | Pulse.Typing.mk_ref | val mk_ref (t: term) : term | val mk_ref (t: term) : term | let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 72,
"end_line": 76,
"start_col": 0,
"start_line": 76
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.ref_lid",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | false | false | false | true | false | let mk_ref (t: term) : term =
| tm_pureapp (tm_fvar (as_fv ref_lid)) None t | false |
Pulse.Typing.fst | Pulse.Typing.extend_env_l | val extend_env_l (f: R.env) (g: env_bindings) : R.env | val extend_env_l (f: R.env) (g: env_bindings) : R.env | let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 113,
"start_col": 0,
"start_line": 107
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: FStar.Stubs.Reflection.Types.env -> g: Pulse.Typing.Env.env_bindings
-> FStar.Stubs.Reflection.Types.env | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Pulse.Typing.Env.env_bindings",
"FStar.List.Tot.Base.fold_right",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.var",
"Pulse.Syntax.Base.term",
"FStar.Reflection.Typing.extend_env",
"FStar.Stubs.Reflection.Types.term",
"Pulse.Elaborate.Pure.elab_term"
] | [] | false | false | false | true | false | let extend_env_l (f: R.env) (g: env_bindings) : R.env =
| L.fold_right (fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f | false |
Pulse.Typing.fst | Pulse.Typing.add_inv | val add_inv (s: comp_st) (v: vprop) : comp_st | val add_inv (s: comp_st) (v: vprop) : comp_st | let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 231,
"start_col": 0,
"start_line": 229
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Pulse.Syntax.Base.comp_st -> v: Pulse.Syntax.Base.vprop -> Pulse.Syntax.Base.comp_st | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.add_frame"
] | [] | false | false | false | true | false | let add_inv (s: comp_st) (v: vprop) : comp_st =
| add_frame s v | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.qmul_shift_384_lemma_eval_fits | val qmul_shift_384_lemma_eval_fits : l:lseq uint64 8 ->
Lemma (let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_v res_b_padded < pow2 128 /\
SD.bn_v res_b_padded = SD.bn_v l / pow2 384) | val qmul_shift_384_lemma_eval_fits : l:lseq uint64 8 ->
Lemma (let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_v res_b_padded < pow2 128 /\
SD.bn_v res_b_padded = SD.bn_v l / pow2 384) | let qmul_shift_384_lemma_eval_fits l =
let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_eval_update_sub 2 res_b 4;
assert (SD.bn_v res_b = SD.bn_v res_b_padded);
SB.bn_rshift_lemma l 6;
SD.bn_eval_bound res_b 2;
assert (SD.bn_v res_b_padded < pow2 128) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 476,
"start_col": 0,
"start_line": 467
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q)
let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
}
val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q)
let lemma_b_pow2_256_plus_a_modq_lseq len a =
lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4
val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q)
let mod_lseq_before_final_lemma a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
mod_lseq_before_final_lemma_aux a;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a);
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256);
calc (==) { //(v c2 * pow2 256 + SD.bn_v r) % S.q;
rhs_p % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 5 p }
SD.bn_v p % S.q;
(==) { }
rhs_m % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 7 m }
SD.bn_v m % S.q;
(==) { }
rhs_a % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 8 a }
SD.bn_v a % S.q;
}
val mod_lseq_lemma: a:lseq uint64 8 -> Lemma (SD.bn_v (mod_lseq a) == SD.bn_v a % S.q)
let mod_lseq_lemma a =
let c0, r = mod_lseq_before_final a in
mod_lseq_before_final_lemma a;
assert ((v c0 * pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c0 * pow2 256 + SD.bn_v r < pow2 256 + pow2 133);
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp = pow2 256 - S.q);
let c1, out = SB.bn_add r tmp in
SB.bn_add_lemma r tmp;
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.small_mod (v c0 + v c1) (pow2 64);
assert (v (c0 +. c1) == v c0 + v c1);
let mask = u64 0 -. (c0 +. c1) in
//let mask = u64 0 -. c1 in
let res = map2 (BB.mask_select mask) out r in
SD.bn_eval_bound r 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v r);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c1);
assert (v c1 = (if SD.bn_v r < S.q then 0 else 1));
if v c0 = 0 then begin
assert (SD.bn_v r % S.q == SD.bn_v a % S.q);
assert (res == mod_short_lseq r);
mod_short_lseq_lemma r;
assert (SD.bn_v res == SD.bn_v a % S.q) end
else begin // v c0 = 1 ==> v c1 = 0
assert ((pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
assert (SD.bn_v r < pow2 133);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.pow2_lt_compat 133 129;
Math.Lemmas.pow2_double_sum 133;
assert (SD.bn_v r + pow2 256 - S.q < pow2 134);
Math.Lemmas.pow2_lt_compat 256 134;
carry_is_zero (v c1) 256 (SD.bn_v out) (SD.bn_v r + pow2 256 - S.q);
assert (v c1 = 0);
assert_norm (pow2 134 < S.q);
assert (SD.bn_v r + pow2 256 - S.q < S.q);
BB.lseq_mask_select_lemma out r mask;
assert (SD.bn_v res == SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.lemma_mod_sub (pow2 256 + SD.bn_v r) S.q 1;
assert (SD.bn_v res % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v res) S.q end
val qmul_shift_383_mod_2_lemma : l:lseq uint64 8 ->
Lemma (v l.[5] / pow2 63 = SD.bn_v l / pow2 383 % 2)
let qmul_shift_383_mod_2_lemma l =
calc (==) {
v l.[5] / pow2 63;
(==) { SD.bn_eval_index l 5 }
SD.bn_v l / pow2 320 % pow2 64 / pow2 63;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 320 384 }
SD.bn_v l % pow2 384 / pow2 320 / pow2 63;
(==) { Math.Lemmas.division_multiplication_lemma (SD.bn_v l % pow2 384) (pow2 320) (pow2 63) }
SD.bn_v l % pow2 384 / (pow2 320 * pow2 63);
(==) { Math.Lemmas.pow2_plus 320 63 }
SD.bn_v l % pow2 384 / pow2 383;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 383 384 }
SD.bn_v l / pow2 383 % pow2 1;
(==) { assert_norm (pow2 1 = 2) }
SD.bn_v l / pow2 383 % 2;
}
val qmul_shift_384_lemma_eval_fits : l:lseq uint64 8 ->
Lemma (let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_v res_b_padded < pow2 128 /\
SD.bn_v res_b_padded = SD.bn_v l / pow2 384) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Lib.Sequence.lseq Lib.IntTypes.uint64 8
-> FStar.Pervasives.Lemma
(ensures
(let res_b = Hacl.Spec.Bignum.bn_rshift l 6 in
let res_b_padded = Lib.Sequence.create 4 (Lib.IntTypes.u64 0) in
let res_b_padded = Lib.Sequence.update_sub res_b_padded 0 2 res_b in
Hacl.Spec.Bignum.Definitions.bn_v res_b_padded < Prims.pow2 128 /\
Hacl.Spec.Bignum.Definitions.bn_v res_b_padded =
Hacl.Spec.Bignum.Definitions.bn_v l / Prims.pow2 384)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Prims.pow2",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Hacl.Spec.Bignum.bn_rshift_lemma",
"Prims.op_Equality",
"Prims.nat",
"Hacl.Spec.Bignum.Definitions.bn_eval_update_sub",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.SEC",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.IntTypes.u64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.bn_rshift"
] | [] | true | false | true | false | false | let qmul_shift_384_lemma_eval_fits l =
| let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_eval_update_sub 2 res_b 4;
assert (SD.bn_v res_b = SD.bn_v res_b_padded);
SB.bn_rshift_lemma l 6;
SD.bn_eval_bound res_b 2;
assert (SD.bn_v res_b_padded < pow2 128) | false |
Pulse.Typing.fst | Pulse.Typing.at_most_one_observable | val at_most_one_observable : o1: Pulse.Syntax.Base.observability -> o2: Pulse.Syntax.Base.observability -> Prims.bool | let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 236,
"start_col": 0,
"start_line": 233
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | o1: Pulse.Syntax.Base.observability -> o2: Pulse.Syntax.Base.observability -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.observability",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Prims.bool"
] | [] | false | false | false | true | false | let at_most_one_observable o1 o2 =
| match o1, o2 with
| Observable, Observable -> false
| _ -> true | false |
|
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.qmul_shift_384_lemma | val qmul_shift_384_lemma (a b:qelem_lseq) :
Lemma (let x = SD.bn_v a * SD.bn_v b / pow2 383 % 2 in
let res = SD.bn_v (qmul_shift_384 a b) in
res < S.q /\ res = SD.bn_v a * SD.bn_v b / pow2 384 + x) | val qmul_shift_384_lemma (a b:qelem_lseq) :
Lemma (let x = SD.bn_v a * SD.bn_v b / pow2 383 % 2 in
let res = SD.bn_v (qmul_shift_384 a b) in
res < S.q /\ res = SD.bn_v a * SD.bn_v b / pow2 384 + x) | let qmul_shift_384_lemma a b =
let l = SB.bn_mul a b in
SB.bn_mul_lemma a b;
assert (SD.bn_v l = SD.bn_v a * SD.bn_v b);
let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
qmul_shift_384_lemma_eval_fits l;
assert (SD.bn_v res_b_padded < pow2 128);
assert (SD.bn_v res_b_padded = SD.bn_v l / pow2 384);
let c, res1_b = SB.bn_add1 res_b_padded (u64 1) in
SB.bn_add1_lemma res_b_padded (u64 1);
assert (v c * pow2 256 + SD.bn_v res1_b = SD.bn_v res_b_padded + 1);
SD.bn_eval_bound res1_b 4;
Math.Lemmas.pow2_lt_compat 256 128;
carry_is_zero (v c) 256 (SD.bn_v res1_b) (SD.bn_v res_b_padded + 1);
assert (v c = 0 /\ SD.bn_v res1_b = SD.bn_v res_b_padded + 1);
let flag = l.[5] >>. 63ul in
assert (v flag = v l.[5] / pow2 63);
qmul_shift_383_mod_2_lemma l;
assert (v flag = SD.bn_v l / pow2 383 % 2);
let mask = u64 0 -. flag in
assert (v mask = (if v flag = 0 then 0 else ones_v U64));
let res = map2 (BB.mask_select mask) res1_b res_b_padded in
BB.lseq_mask_select_lemma res1_b res_b_padded mask;
assert (res == (if v flag = 0 then res_b_padded else res1_b)) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 513,
"start_col": 0,
"start_line": 484
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q)
let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
}
val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q)
let lemma_b_pow2_256_plus_a_modq_lseq len a =
lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4
val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q)
let mod_lseq_before_final_lemma a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
mod_lseq_before_final_lemma_aux a;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a);
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256);
calc (==) { //(v c2 * pow2 256 + SD.bn_v r) % S.q;
rhs_p % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 5 p }
SD.bn_v p % S.q;
(==) { }
rhs_m % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 7 m }
SD.bn_v m % S.q;
(==) { }
rhs_a % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 8 a }
SD.bn_v a % S.q;
}
val mod_lseq_lemma: a:lseq uint64 8 -> Lemma (SD.bn_v (mod_lseq a) == SD.bn_v a % S.q)
let mod_lseq_lemma a =
let c0, r = mod_lseq_before_final a in
mod_lseq_before_final_lemma a;
assert ((v c0 * pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c0 * pow2 256 + SD.bn_v r < pow2 256 + pow2 133);
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp = pow2 256 - S.q);
let c1, out = SB.bn_add r tmp in
SB.bn_add_lemma r tmp;
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.small_mod (v c0 + v c1) (pow2 64);
assert (v (c0 +. c1) == v c0 + v c1);
let mask = u64 0 -. (c0 +. c1) in
//let mask = u64 0 -. c1 in
let res = map2 (BB.mask_select mask) out r in
SD.bn_eval_bound r 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v r);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c1);
assert (v c1 = (if SD.bn_v r < S.q then 0 else 1));
if v c0 = 0 then begin
assert (SD.bn_v r % S.q == SD.bn_v a % S.q);
assert (res == mod_short_lseq r);
mod_short_lseq_lemma r;
assert (SD.bn_v res == SD.bn_v a % S.q) end
else begin // v c0 = 1 ==> v c1 = 0
assert ((pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
assert (SD.bn_v r < pow2 133);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.pow2_lt_compat 133 129;
Math.Lemmas.pow2_double_sum 133;
assert (SD.bn_v r + pow2 256 - S.q < pow2 134);
Math.Lemmas.pow2_lt_compat 256 134;
carry_is_zero (v c1) 256 (SD.bn_v out) (SD.bn_v r + pow2 256 - S.q);
assert (v c1 = 0);
assert_norm (pow2 134 < S.q);
assert (SD.bn_v r + pow2 256 - S.q < S.q);
BB.lseq_mask_select_lemma out r mask;
assert (SD.bn_v res == SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.lemma_mod_sub (pow2 256 + SD.bn_v r) S.q 1;
assert (SD.bn_v res % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v res) S.q end
val qmul_shift_383_mod_2_lemma : l:lseq uint64 8 ->
Lemma (v l.[5] / pow2 63 = SD.bn_v l / pow2 383 % 2)
let qmul_shift_383_mod_2_lemma l =
calc (==) {
v l.[5] / pow2 63;
(==) { SD.bn_eval_index l 5 }
SD.bn_v l / pow2 320 % pow2 64 / pow2 63;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 320 384 }
SD.bn_v l % pow2 384 / pow2 320 / pow2 63;
(==) { Math.Lemmas.division_multiplication_lemma (SD.bn_v l % pow2 384) (pow2 320) (pow2 63) }
SD.bn_v l % pow2 384 / (pow2 320 * pow2 63);
(==) { Math.Lemmas.pow2_plus 320 63 }
SD.bn_v l % pow2 384 / pow2 383;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 383 384 }
SD.bn_v l / pow2 383 % pow2 1;
(==) { assert_norm (pow2 1 = 2) }
SD.bn_v l / pow2 383 % 2;
}
val qmul_shift_384_lemma_eval_fits : l:lseq uint64 8 ->
Lemma (let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_v res_b_padded < pow2 128 /\
SD.bn_v res_b_padded = SD.bn_v l / pow2 384)
let qmul_shift_384_lemma_eval_fits l =
let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
SD.bn_eval_update_sub 2 res_b 4;
assert (SD.bn_v res_b = SD.bn_v res_b_padded);
SB.bn_rshift_lemma l 6;
SD.bn_eval_bound res_b 2;
assert (SD.bn_v res_b_padded < pow2 128)
val qmul_shift_384_lemma (a b:qelem_lseq) :
Lemma (let x = SD.bn_v a * SD.bn_v b / pow2 383 % 2 in
let res = SD.bn_v (qmul_shift_384 a b) in
res < S.q /\ res = SD.bn_v a * SD.bn_v b / pow2 384 + x) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.K256.Scalar.qelem_lseq -> b: Hacl.Spec.K256.Scalar.qelem_lseq
-> FStar.Pervasives.Lemma
(ensures
(let x =
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 383 %
2
in
let res = Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.K256.Scalar.qmul_shift_384 a b) in
res < Spec.K256.PointOps.q /\
res =
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 384 +
x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.K256.Scalar.qelem_lseq",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.bool",
"Prims.unit",
"Hacl.Spec.Bignum.Base.lseq_mask_select_lemma",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.Sequence.map2",
"Lib.IntTypes.ones_v",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.u64",
"Prims.op_Modulus",
"Prims.op_Division",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Spec.K256.Scalar.Lemmas.qmul_shift_383_mod_2_lemma",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.op_Greater_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_Addition",
"Hacl.Spec.K256.Scalar.Lemmas.carry_is_zero",
"FStar.Math.Lemmas.pow2_lt_compat",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"FStar.Mul.op_Star",
"Hacl.Spec.Bignum.bn_add1_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add1",
"Hacl.Spec.K256.Scalar.Lemmas.qmul_shift_384_lemma_eval_fits",
"Lib.Sequence.sub",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Lib.Sequence.create",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.bn_rshift",
"Hacl.Spec.Bignum.bn_mul_lemma",
"Hacl.Spec.Bignum.bn_mul"
] | [] | false | false | true | false | false | let qmul_shift_384_lemma a b =
| let l = SB.bn_mul a b in
SB.bn_mul_lemma a b;
assert (SD.bn_v l = SD.bn_v a * SD.bn_v b);
let res_b = SB.bn_rshift l 6 in
let res_b_padded = create 4 (u64 0) in
let res_b_padded = update_sub res_b_padded 0 2 res_b in
qmul_shift_384_lemma_eval_fits l;
assert (SD.bn_v res_b_padded < pow2 128);
assert (SD.bn_v res_b_padded = SD.bn_v l / pow2 384);
let c, res1_b = SB.bn_add1 res_b_padded (u64 1) in
SB.bn_add1_lemma res_b_padded (u64 1);
assert (v c * pow2 256 + SD.bn_v res1_b = SD.bn_v res_b_padded + 1);
SD.bn_eval_bound res1_b 4;
Math.Lemmas.pow2_lt_compat 256 128;
carry_is_zero (v c) 256 (SD.bn_v res1_b) (SD.bn_v res_b_padded + 1);
assert (v c = 0 /\ SD.bn_v res1_b = SD.bn_v res_b_padded + 1);
let flag = l.[ 5 ] >>. 63ul in
assert (v flag = v l.[ 5 ] / pow2 63);
qmul_shift_383_mod_2_lemma l;
assert (v flag = SD.bn_v l / pow2 383 % 2);
let mask = u64 0 -. flag in
assert (v mask = (if v flag = 0 then 0 else ones_v U64));
let res = map2 (BB.mask_select mask) res1_b res_b_padded in
BB.lseq_mask_select_lemma res1_b res_b_padded mask;
assert (res == (if v flag = 0 then res_b_padded else res1_b)) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_add_lemma_carry_is_zero | val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 266,
"start_col": 0,
"start_line": 254
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat ->
resLen: Lib.IntTypes.size_nat{2 + len <= resLen /\ 4 <= resLen} ->
d: Prims.nat ->
a: Lib.Sequence.lseq Lib.IntTypes.uint64 len ->
e: Lib.Sequence.lseq Lib.IntTypes.uint64 4 ->
f: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Bignum.Definitions.bn_v a < Prims.pow2 d /\ d + 129 < 64 * resLen /\ 256 <= f /\
d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures
(let _ = Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add len resLen a e in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (64 * resLen) + Hacl.Spec.Bignum.Definitions.bn_v res =
Hacl.Spec.Bignum.Definitions.bn_v a * (Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v e /\ Lib.IntTypes.v c = 0 /\
Hacl.Spec.Bignum.Definitions.bn_v a * (Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v e <
Prims.pow2 (d + 129) + Prims.pow2 256)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.size_nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.nat",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.unit",
"Hacl.Spec.K256.Scalar.Lemmas.carry_is_zero",
"FStar.Mul.op_Star",
"FStar.Math.Lemmas.pow2_lt_compat",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Math.Lemmas.pow2_double_sum",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.op_Subtraction",
"Spec.K256.PointOps.q",
"Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add"
] | [] | false | false | true | false | false | let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
| let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m) | false |
Pulse.Typing.fst | Pulse.Typing.bind_comp_compatible | val bind_comp_compatible (c1 c2: comp_st) : prop | val bind_comp_compatible (c1 c2: comp_st) : prop | let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 262,
"start_col": 0,
"start_line": 255
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.st_comp",
"Prims.l_True",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.observability",
"Prims.l_and",
"Prims.eq2",
"Prims.b2t",
"Pulse.Typing.at_most_one_observable",
"Prims.l_False",
"Prims.prop"
] | [] | false | false | false | true | true | let bind_comp_compatible (c1 c2: comp_st) : prop =
| match c1, c2 with
| C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.finv | val finv: inp:elem -> out:elem{out == fpow inp (pow2 255 - 21)} | val finv: inp:elem -> out:elem{out == fpow inp (pow2 255 - 21)} | let finv i =
let a, t0 = finv0 i in
(* 2^255 - 21 *) let o = fmul t0 a in
lemma_pow_add i (pow2 255 - pow2 5) 11;
assert_norm (pow2 255 - pow2 5 + 11 = pow2 255 - 21);
assert (o == pow i (pow2 255 - 21));
o | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 171,
"start_col": 0,
"start_line": 165
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m))
let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m)
val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b))
let lemma_pow_double a b =
lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b)
val fsquare_times: inp:elem -> n:pos -> out:elem{out == pow inp (pow2 n)}
let fsquare_times inp n =
let out = fsqr inp in
lemma_pow_one inp;
lemma_pow_add inp 1 1;
assert_norm (pow2 1 = 2);
assert (out == pow inp (pow2 1));
let out =
Lib.LoopCombinators.repeati_inductive #elem (n - 1)
(fun i out -> out == pow inp (pow2 (i + 1)))
(fun i out ->
assert (out == pow inp (pow2 (i + 1)));
let res = fsqr out in
calc (==) {
fmul out out;
(==) { lemma_pow_add inp (pow2 (i + 1)) (pow2 (i + 1)) }
pow inp (pow2 (i + 1) + pow2 (i + 1));
(==) { Math.Lemmas.pow2_double_sum (i + 1) }
pow inp (pow2 (i + 2));
};
res) out in
assert (out == pow inp (pow2 n));
out
let pow_t0:nat =
assert_norm (pow2 255 - pow2 5 > 0);
pow2 255 - pow2 5
val finv0: inp:elem ->
Pure (tuple2 elem elem)
(requires True)
(ensures fun (a, t0) ->
a == pow inp 11 /\
t0 == pow inp pow_t0)
let finv0 i =
(* 2 *) let a = fsquare_times i 1 in
assert (a == pow i 2);
(* 8 *) let t0 = fsquare_times a 2 in
assert (t0 == pow a 4);
lemma_pow_mul i 2 4;
assert (t0 == pow i 8);
(* 9 *) let b = fmul t0 i in
lemma_pow_one i;
lemma_pow_add i 8 1;
assert (b == pow i 9);
(* 11 *) let a = fmul b a in
lemma_pow_add i 9 2;
assert (a == pow i 11);
(* 22 *) let t0 = fsquare_times a 1 in
lemma_pow_mul i 11 2;
assert (t0 == pow i 22);
(* 2^5 - 2^0 = 31 *) let b = fmul t0 b in
lemma_pow_add i 22 9;
assert (b == pow i 31);
(* 2^10 - 2^5 *) let t0 = fsquare_times b 5 in
lemma_pow_mul i 31 (pow2 5);
assert_norm (31 * pow2 5 = pow2 10 - pow2 5);
assert (t0 == pow i (pow2 10 - pow2 5));
(* 2^10 - 2^0 *) let b = fmul t0 b in
assert_norm (31 = pow2 5 - 1);
lemma_pow_add i (pow2 10 - pow2 5) (pow2 5 - 1);
assert (b == pow i (pow2 10 - 1));
(* 2^20 - 2^10 *) let t0 = fsquare_times b 10 in
lemma_pow_mul i (pow2 10 - 1) (pow2 10);
assert_norm ((pow2 10 - 1) * pow2 10 == pow2 20 - pow2 10);
assert (t0 == pow i (pow2 20 - pow2 10));
(* 2^20 - 2^0 *) let c = fmul t0 b in
lemma_pow_add i (pow2 20 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 20 - pow2 10 + pow2 10 - 1 = pow2 20 - 1);
assert (c == pow i (pow2 20 - 1));
(* 2^40 - 2^20 *) let t0 = fsquare_times c 20 in
lemma_pow_mul i (pow2 20 - 1) (pow2 20);
assert_norm ((pow2 20 - 1) * pow2 20 = pow2 40 - pow2 20);
assert (t0 == pow i (pow2 40 - pow2 20));
(* 2^40 - 2^0 *) let t0 = fmul t0 c in
lemma_pow_add i (pow2 40 -pow2 20) (pow2 20 - 1);
assert_norm (pow2 40 - pow2 20 + pow2 20 - 1 = pow2 40 - 1);
assert (t0 == pow i (pow2 40 - 1));
(* 2^50 - 2^10 *) let t0 = fsquare_times t0 10 in
lemma_pow_mul i (pow2 40 - 1) (pow2 10);
assert_norm ((pow2 40 - 1) * pow2 10 = pow2 50 - pow2 10);
assert (t0 == pow i (pow2 50 - pow2 10));
(* 2^50 - 2^0 *) let b = fmul t0 b in
lemma_pow_add i (pow2 50 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 50 - pow2 10 + pow2 10 - 1 = pow2 50 - 1);
assert (b == pow i (pow2 50 - 1));
(* 2^100 - 2^50 *) let t0 = fsquare_times b 50 in
lemma_pow_mul i (pow2 50 - 1) (pow2 50);
assert_norm ((pow2 50 - 1) * pow2 50 = pow2 100 - pow2 50);
assert (t0 == pow i (pow2 100 - pow2 50));
(* 2^100 - 2^0 *) let c = fmul t0 b in
lemma_pow_add i (pow2 100 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 100 - pow2 50 + pow2 50 - 1 = pow2 100 - 1);
assert (c == pow i (pow2 100 - 1));
(* 2^200 - 2^100 *) let t0 = fsquare_times c 100 in
lemma_pow_mul i (pow2 100 - 1) (pow2 100);
assert_norm ((pow2 100 - 1) * pow2 100 = pow2 200 - pow2 100);
assert (t0 == pow i (pow2 200 - pow2 100));
(* 2^200 - 2^0 *) let t0 = fmul t0 c in
lemma_pow_add i (pow2 200 - pow2 100) (pow2 100 - 1);
assert_norm (pow2 200 - pow2 100 + pow2 100 - 1 = pow2 200 - 1);
assert (t0 == pow i (pow2 200 - 1));
(* 2^250 - 2^50 *) let t0 = fsquare_times t0 50 in
lemma_pow_mul i (pow2 200 - 1) (pow2 50);
assert_norm ((pow2 200 - 1) * pow2 50 = pow2 250 - pow2 50);
assert (t0 == pow i (pow2 250 - pow2 50));
(* 2^250 - 2^0 *) let t0 = fmul t0 b in
lemma_pow_add i (pow2 250 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 250 - pow2 50 + pow2 50 - 1 = pow2 250 - 1);
assert (t0 == pow i (pow2 250 - 1));
(* 2^255 - 2^5 *) let t0 = fsquare_times t0 5 in
lemma_pow_mul i (pow2 250 - 1) (pow2 5);
assert_norm ((pow2 250 - 1) * pow2 5 = pow2 255 - pow2 5);
assert (t0 == pow i (pow2 255 - pow2 5));
a, t0 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inp: Spec.Curve25519.elem
-> out: Spec.Curve25519.elem{out == Spec.Curve25519.fpow inp (Prims.pow2 255 - 21)} | Prims.Tot | [
"total"
] | [] | [
"Spec.Curve25519.elem",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Curve25519.Finv.pow",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Hacl.Spec.Curve25519.Finv.lemma_pow_add",
"Spec.Curve25519.fmul",
"Spec.Curve25519.fpow",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Curve25519.Finv.finv0"
] | [] | false | false | false | false | false | let finv i =
| let a, t0 = finv0 i in
let o = fmul t0 a in
lemma_pow_add i (pow2 255 - pow2 5) 11;
assert_norm (pow2 255 - pow2 5 + 11 = pow2 255 - 21);
assert (o == pow i (pow2 255 - 21));
o | false |
Pulse.Typing.fst | Pulse.Typing.non_informative_witness_t | val non_informative_witness_t (u: universe) (t: term) : term | val non_informative_witness_t (u: universe) (t: term) : term | let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 295,
"start_col": 0,
"start_line": 291
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u408: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.non_informative_witness_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | false | false | false | true | false | let non_informative_witness_t (u: universe) (t: term) : term =
| tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t | false |
Pulse.Typing.fst | Pulse.Typing.named_binder | val named_binder : x: Pulse.Syntax.Base.ppname -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder | let named_binder (x:ppname) (t:term) = mk_binder_ppname t x | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 320,
"start_col": 0,
"start_line": 320
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.ppname -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.mk_binder_ppname",
"Pulse.Syntax.Base.binder"
] | [] | false | false | false | true | false | let named_binder (x: ppname) (t: term) =
| mk_binder_ppname t x | false |
|
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mod_lseq_lemma | val mod_lseq_lemma: a:lseq uint64 8 -> Lemma (SD.bn_v (mod_lseq a) == SD.bn_v a % S.q) | val mod_lseq_lemma: a:lseq uint64 8 -> Lemma (SD.bn_v (mod_lseq a) == SD.bn_v a % S.q) | let mod_lseq_lemma a =
let c0, r = mod_lseq_before_final a in
mod_lseq_before_final_lemma a;
assert ((v c0 * pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c0 * pow2 256 + SD.bn_v r < pow2 256 + pow2 133);
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp = pow2 256 - S.q);
let c1, out = SB.bn_add r tmp in
SB.bn_add_lemma r tmp;
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.small_mod (v c0 + v c1) (pow2 64);
assert (v (c0 +. c1) == v c0 + v c1);
let mask = u64 0 -. (c0 +. c1) in
//let mask = u64 0 -. c1 in
let res = map2 (BB.mask_select mask) out r in
SD.bn_eval_bound r 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v r);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c1);
assert (v c1 = (if SD.bn_v r < S.q then 0 else 1));
if v c0 = 0 then begin
assert (SD.bn_v r % S.q == SD.bn_v a % S.q);
assert (res == mod_short_lseq r);
mod_short_lseq_lemma r;
assert (SD.bn_v res == SD.bn_v a % S.q) end
else begin // v c0 = 1 ==> v c1 = 0
assert ((pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
assert (SD.bn_v r < pow2 133);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.pow2_lt_compat 133 129;
Math.Lemmas.pow2_double_sum 133;
assert (SD.bn_v r + pow2 256 - S.q < pow2 134);
Math.Lemmas.pow2_lt_compat 256 134;
carry_is_zero (v c1) 256 (SD.bn_v out) (SD.bn_v r + pow2 256 - S.q);
assert (v c1 = 0);
assert_norm (pow2 134 < S.q);
assert (SD.bn_v r + pow2 256 - S.q < S.q);
BB.lseq_mask_select_lemma out r mask;
assert (SD.bn_v res == SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.lemma_mod_sub (pow2 256 + SD.bn_v r) S.q 1;
assert (SD.bn_v res % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v res) S.q end | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 437,
"start_col": 0,
"start_line": 387
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q)
let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
}
val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q)
let lemma_b_pow2_256_plus_a_modq_lseq len a =
lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4
val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q)
let mod_lseq_before_final_lemma a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
mod_lseq_before_final_lemma_aux a;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a);
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256);
calc (==) { //(v c2 * pow2 256 + SD.bn_v r) % S.q;
rhs_p % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 5 p }
SD.bn_v p % S.q;
(==) { }
rhs_m % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 7 m }
SD.bn_v m % S.q;
(==) { }
rhs_a % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 8 a }
SD.bn_v a % S.q;
} | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.Sequence.lseq Lib.IntTypes.uint64 8
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.K256.Scalar.mod_lseq a) ==
Hacl.Spec.Bignum.Definitions.bn_v a % Spec.K256.PointOps.q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.K256.Scalar.qelem_lseq",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Modulus",
"Spec.K256.PointOps.q",
"Prims.unit",
"Hacl.Spec.K256.Scalar.Lemmas.mod_short_lseq_lemma",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.K256.Scalar.mod_short_lseq",
"Prims.bool",
"FStar.Math.Lemmas.small_mod",
"FStar.Math.Lemmas.lemma_mod_sub",
"Prims.op_Addition",
"Prims.pow2",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Base.lseq_mask_select_lemma",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Pervasives.assert_norm",
"Hacl.Spec.K256.Scalar.Lemmas.carry_is_zero",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.Math.Lemmas.pow2_double_sum",
"FStar.Mul.op_Star",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_get_carry_from_bn_add",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_check_overflow",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.int_t",
"Lib.Sequence.map2",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.u64",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_is_qas_nat",
"Lib.Sequence.create4",
"Hacl.Spec.K256.Scalar.qelem4",
"Hacl.Spec.K256.Scalar.make_pow2_256_minus_order_k256",
"Hacl.Spec.K256.Scalar.Lemmas.mod_lseq_before_final_lemma",
"Hacl.Spec.K256.Scalar.mod_lseq_before_final"
] | [] | false | false | true | false | false | let mod_lseq_lemma a =
| let c0, r = mod_lseq_before_final a in
mod_lseq_before_final_lemma a;
assert ((v c0 * pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c0 * pow2 256 + SD.bn_v r < pow2 256 + pow2 133);
let t0, t1, t2, t3 = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp = pow2 256 - S.q);
let c1, out = SB.bn_add r tmp in
SB.bn_add_lemma r tmp;
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.small_mod (v c0 + v c1) (pow2 64);
assert (v (c0 +. c1) == v c0 + v c1);
let mask = u64 0 -. (c0 +. c1) in
let res = map2 (BB.mask_select mask) out r in
SD.bn_eval_bound r 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v r);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c1);
assert (v c1 = (if SD.bn_v r < S.q then 0 else 1));
if v c0 = 0
then
(assert (SD.bn_v r % S.q == SD.bn_v a % S.q);
assert (res == mod_short_lseq r);
mod_short_lseq_lemma r;
assert (SD.bn_v res == SD.bn_v a % S.q))
else
(assert ((pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q);
assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q);
assert (SD.bn_v r < pow2 133);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.pow2_lt_compat 133 129;
Math.Lemmas.pow2_double_sum 133;
assert (SD.bn_v r + pow2 256 - S.q < pow2 134);
Math.Lemmas.pow2_lt_compat 256 134;
carry_is_zero (v c1) 256 (SD.bn_v out) (SD.bn_v r + pow2 256 - S.q);
assert (v c1 = 0);
assert_norm (pow2 134 < S.q);
assert (SD.bn_v r + pow2 256 - S.q < S.q);
BB.lseq_mask_select_lemma out r mask;
assert (SD.bn_v res == SD.bn_v r + pow2 256 - S.q);
Math.Lemmas.lemma_mod_sub (pow2 256 + SD.bn_v r) S.q 1;
assert (SD.bn_v res % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v res) S.q) | false |
Pulse.Typing.fst | Pulse.Typing.comp_elim_exists | val comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp | val comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp | let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 310,
"start_col": 0,
"start_line": 303
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u424: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
p: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.nvar
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.nvar",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Typing.mk_erased",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.elim_exists_post",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp =
| C_STGhost
({
u = u;
res = mk_erased u t;
pre = tm_exists_sl u (as_binder t) p;
post = elim_exists_post u t p x
}) | false |
Pulse.Typing.fst | Pulse.Typing.elim_exists_post | val elim_exists_post (u: universe) (t p: term) (x: nvar) : term | val elim_exists_post (u: universe) (t p: term) (x: nvar) : term | let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 301,
"start_col": 0,
"start_line": 297
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u416: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
p: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.nvar
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.nvar",
"Pulse.Syntax.Naming.close_term",
"FStar.Pervasives.Native.snd",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.mk_reveal",
"Pulse.Syntax.Pure.term_of_nvar"
] | [] | false | false | false | true | false | let elim_exists_post (u: universe) (t p: term) (x: nvar) : term =
| let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mod_lseq_before_final_lemma | val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q) | val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q) | let mod_lseq_before_final_lemma a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
mod_lseq_before_final_lemma_aux a;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a);
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256);
calc (==) { //(v c2 * pow2 256 + SD.bn_v r) % S.q;
rhs_p % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 5 p }
SD.bn_v p % S.q;
(==) { }
rhs_m % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 7 m }
SD.bn_v m % S.q;
(==) { }
rhs_a % S.q;
(==) { lemma_b_pow2_256_plus_a_modq_lseq 8 a }
SD.bn_v a % S.q;
} | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 383,
"start_col": 0,
"start_line": 356
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q)
let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
}
val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len ->
Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q)
let lemma_b_pow2_256_plus_a_modq_lseq len a =
lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4)));
SD.bn_eval_split_i a 4
val mod_lseq_before_final_lemma: a:lseq uint64 8 ->
Lemma (let (c, res) = mod_lseq_before_final a in
v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\
(v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.Sequence.lseq Lib.IntTypes.uint64 8
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.K256.Scalar.mod_lseq_before_final a in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 256 + Hacl.Spec.Bignum.Definitions.bn_v res <
Prims.pow2 133 + Prims.pow2 256 /\
(Lib.IntTypes.v c * Prims.pow2 256 + Hacl.Spec.Bignum.Definitions.bn_v res) %
Spec.K256.PointOps.q ==
Hacl.Spec.Bignum.Definitions.bn_v a % Spec.K256.PointOps.q)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Spec.K256.PointOps.q",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_b_pow2_256_plus_a_modq_lseq",
"Prims.squash",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.pow2",
"Prims.op_Equality",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Hacl.Spec.K256.Scalar.Lemmas.mod_lseq_before_final_lemma_aux",
"Lib.Sequence.sub",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add"
] | [] | false | false | true | false | false | let mod_lseq_before_final_lemma a =
| let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
mod_lseq_before_final_lemma_aux a;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a);
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256);
calc ( == ) {
rhs_p % S.q;
( == ) { lemma_b_pow2_256_plus_a_modq_lseq 5 p }
SD.bn_v p % S.q;
( == ) { () }
rhs_m % S.q;
( == ) { lemma_b_pow2_256_plus_a_modq_lseq 7 m }
SD.bn_v m % S.q;
( == ) { () }
rhs_a % S.q;
( == ) { lemma_b_pow2_256_plus_a_modq_lseq 8 a }
SD.bn_v a % S.q;
} | false |
Pulse.Typing.fst | Pulse.Typing.comp_intro_pure | val comp_intro_pure : p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 318,
"start_col": 0,
"start_line": 312
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u_zero",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Base.tm_emp",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_intro_pure (p: term) =
| C_STGhost ({ u = u_zero; res = tm_unit; pre = tm_emp; post = tm_pure p }) | false |
|
Pulse.Typing.fst | Pulse.Typing.comp_while_cond | val comp_while_cond (x: ppname) (inv: term) : comp | val comp_while_cond (x: ppname) (inv: term) : comp | let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 348,
"start_col": 0,
"start_line": 341
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_while_cond (x: ppname) (inv: term) : comp =
| C_ST ({ u = u0; res = tm_bool; pre = tm_exists_sl u0 (named_binder x tm_bool) inv; post = inv }) | false |
Pulse.Typing.fst | Pulse.Typing.comp_intro_exists_erased | val comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp | val comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp | let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 338,
"start_col": 0,
"start_line": 331
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u446: Pulse.Syntax.Base.universe ->
b: Pulse.Syntax.Base.binder ->
p: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.mk_reveal",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp =
| C_STGhost
({
u = u0;
res = tm_unit;
pre = open_term' p (mk_reveal u b.binder_ty e) 0;
post = tm_exists_sl u b p
}) | false |
Pulse.Typing.fst | Pulse.Typing.mk_tuple2 | val mk_tuple2 (u1 u2: universe) (t1 t2: term) : term | val mk_tuple2 (u1 u2: universe) (t1 t2: term) : term | let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 372,
"start_col": 0,
"start_line": 368
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u1: Pulse.Syntax.Base.universe ->
u2: Pulse.Syntax.Base.universe ->
t1: Pulse.Syntax.Base.term ->
t2: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.tuple2_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | false | false | false | true | false | let mk_tuple2 (u1 u2: universe) (t1 t2: term) : term =
| tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 | false |
Pulse.Typing.fst | Pulse.Typing.comp_while_body | val comp_while_body (x: ppname) (inv: term) : comp | val comp_while_body (x: ppname) (inv: term) : comp | let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 357,
"start_col": 0,
"start_line": 350
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.tm_true",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_while_body (x: ppname) (inv: term) : comp =
| C_ST
({
u = u0;
res = tm_unit;
pre = open_term' inv tm_true 0;
post = tm_exists_sl u0 (named_binder x tm_bool) inv
}) | false |
Pulse.Typing.fst | Pulse.Typing.mk_fst | val mk_fst (u1 u2: universe) (a1 a2 e: term) : term | val mk_fst (u1 u2: universe) (a1 a2 e: term) : term | let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 378,
"start_col": 0,
"start_line": 374
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u1: Pulse.Syntax.Base.universe ->
u2: Pulse.Syntax.Base.universe ->
a1: Pulse.Syntax.Base.term ->
a2: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.fst_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.Implicit",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let mk_fst (u1 u2: universe) (a1 a2 e: term) : term =
| tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit)
a2)
None
e | false |
Pulse.Typing.fst | Pulse.Typing.mk_snd | val mk_snd (u1 u2: universe) (a1 a2 e: term) : term | val mk_snd (u1 u2: universe) (a1 a2 e: term) : term | let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 384,
"start_col": 0,
"start_line": 380
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u1: Pulse.Syntax.Base.universe ->
u2: Pulse.Syntax.Base.universe ->
a1: Pulse.Syntax.Base.term ->
a2: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.snd_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.Implicit",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let mk_snd (u1 u2: universe) (a1 a2 e: term) : term =
| tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit)
a2)
None
e | false |
Pulse.Typing.fst | Pulse.Typing.par_post | val par_post (uL uR: universe) (aL aR postL postR: term) (x: var) : term | val par_post (uL uR: universe) (aL aR postL postR: term) (x: var) : term | let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 392,
"start_col": 0,
"start_line": 386
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
uL: Pulse.Syntax.Base.universe ->
uR: Pulse.Syntax.Base.universe ->
aL: Pulse.Syntax.Base.term ->
aR: Pulse.Syntax.Base.term ->
postL: Pulse.Syntax.Base.term ->
postR: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.var
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.close_term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.mk_snd",
"Pulse.Typing.mk_fst",
"Pulse.Syntax.Pure.term_of_no_name_var"
] | [] | false | false | false | true | false | let par_post (uL uR: universe) (aL aR postL postR: term) (x: var) : term =
| let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x | false |
Pulse.Typing.fst | Pulse.Typing.comp_intro_exists | val comp_intro_exists (u: universe) (b: binder) (p e: term) : comp | val comp_intro_exists (u: universe) (b: binder) (p e: term) : comp | let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 329,
"start_col": 0,
"start_line": 322
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u438: Pulse.Syntax.Base.universe ->
b: Pulse.Syntax.Base.binder ->
p: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_intro_exists (u: universe) (b: binder) (p e: term) : comp =
| C_STGhost ({ u = u0; res = tm_unit; pre = open_term' p e 0; post = tm_exists_sl u b p }) | false |
Pulse.Typing.fst | Pulse.Typing.comp_while | val comp_while (x: ppname) (inv: term) : comp | val comp_while (x: ppname) (inv: term) : comp | let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 366,
"start_col": 0,
"start_line": 359
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.tm_false",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_while (x: ppname) (inv: term) : comp =
| C_ST
({
u = u0;
res = tm_unit;
pre = tm_exists_sl u0 (named_binder x tm_bool) inv;
post = open_term' inv tm_false 0
}) | false |
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_body_pre | val comp_withlocal_body_pre (pre: vprop) (init_t r init: term) : vprop | val comp_withlocal_body_pre (pre: vprop) (init_t r init: term) : vprop | let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 410,
"start_col": 0,
"start_line": 409
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pre: Pulse.Syntax.Base.vprop ->
init_t: Pulse.Syntax.Base.term ->
r: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Typing.mk_pts_to"
] | [] | false | false | false | true | false | let comp_withlocal_body_pre (pre: vprop) (init_t r init: term) : vprop =
| tm_star pre (mk_pts_to init_t r init) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.mod_lseq_before_final_lemma_aux | val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256) | val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256) | let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256) | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 327,
"start_col": 0,
"start_line": 309
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.Sequence.lseq Lib.IntTypes.uint64 8
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add 4
7
(Lib.Sequence.sub a 4 4)
(Lib.Sequence.sub a 0 4)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c0 m = _ in
let _ =
Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add 3
5
(Lib.Sequence.sub m 4 3)
(Lib.Sequence.sub m 0 4)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 p = _ in
let _ =
Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add 1
4
(Lib.Sequence.sub p 4 1)
(Lib.Sequence.sub p 0 4)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c2 r = _ in
let rhs_a =
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub a 4 4) *
(Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub a 0 4)
in
let rhs_m =
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub m 4 3) *
(Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub m 0 4)
in
let rhs_p =
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub p 4 1) *
(Prims.pow2 256 - Spec.K256.PointOps.q) +
Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.sub p 0 4)
in
Lib.IntTypes.v c0 = 0 /\ Hacl.Spec.Bignum.Definitions.bn_v m = rhs_a /\
Lib.IntTypes.v c1 = 0 /\ Hacl.Spec.Bignum.Definitions.bn_v p = rhs_m /\
Lib.IntTypes.v c2 * Prims.pow2 256 + Hacl.Spec.Bignum.Definitions.bn_v r = rhs_p /\
rhs_p < Prims.pow2 133 + Prims.pow2 256)
<:
Type0)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.pow2",
"Prims.unit",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Sequence.sub",
"Prims.op_Subtraction",
"Spec.K256.PointOps.q",
"Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_add_lemma",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_p_bound",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add",
"Prims.l_and",
"Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_add_lemma_carry_is_zero",
"Hacl.Spec.K256.Scalar.Lemmas.lemma_m_bound",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound"
] | [] | false | false | true | false | false | let mod_lseq_before_final_lemma_aux a =
| let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256) | false |
Pulse.Typing.fst | Pulse.Typing.mk_array_pts_to | val mk_array_pts_to (a arr v: term) : term | val mk_array_pts_to (a arr v: term) : term | let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 437,
"start_col": 0,
"start_line": 432
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.full_perm_lid",
"Pulse.Reflection.Util.array_pts_to_lid"
] | [] | false | false | false | true | false | let mk_array_pts_to (a arr v: term) : term =
| let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | false |
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_array_body_post | val comp_withlocal_array_body_post (post a arr: term) : term | val comp_withlocal_array_body_post (post a arr: term) : term | let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 96,
"end_line": 464,
"start_col": 0,
"start_line": 463
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | post: Pulse.Syntax.Base.term -> a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Pure.u0",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.mk_seq",
"Pulse.Typing.mk_array_pts_to",
"Pulse.Syntax.Pure.null_bvar"
] | [] | false | false | false | true | false | let comp_withlocal_array_body_post (post a arr: term) : term =
| tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | false |
Hacl.Spec.Chacha20.Equiv.fst | Hacl.Spec.Chacha20.Equiv.line_lemma_i | val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 156,
"start_col": 0,
"start_line": 149
} | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Chacha20.Vec.idx ->
b: Hacl.Spec.Chacha20.Vec.idx ->
d: Hacl.Spec.Chacha20.Vec.idx ->
s: Lib.IntTypes.rotval Lib.IntTypes.U32 ->
m: Hacl.Spec.Chacha20.Vec.state w ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.line a
b
d
s
m)).[ i ]
(Spec.Chacha20.line a b d s (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.idx",
"Lib.IntTypes.rotval",
"Lib.IntTypes.U32",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.rotate_left",
"Lib.IntTypes.logxor",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Lib.IntVector.op_Less_Less_Less_Bar",
"Lib.IntVector.op_Hat_Bar",
"Prims.unit",
"Lib.IntTypes.add_mod",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntVector.op_Plus_Bar"
] | [] | true | false | true | false | false | let line_lemma_i #w a b d s m0 i =
| let m0_s = (transpose_state #w m0).[ i ] in
let m1 = m0.[ a ] <- m0.[ a ] +| m0.[ b ] in
let m1_s = m0_s.[ a ] <- m0_s.[ a ] +. m0_s.[ b ] in
eq_intro (transpose_state m1).[ i ] m1_s;
let m2 = m1.[ d ] <- (m1.[ d ] ^| m1.[ a ]) <<<| s in
let m2_s = m1_s.[ d ] <- (m1_s.[ d ] ^. m1_s.[ a ]) <<<. s in
eq_intro (transpose_state m2).[ i ] m2_s | false |
Pulse.Typing.fst | Pulse.Typing.mk_array | val mk_array (a: term) : term | val mk_array (a: term) : term | let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 425,
"start_col": 0,
"start_line": 424
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.array_lid",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | false | false | false | true | false | let mk_array (a: term) : term =
| tm_pureapp (tm_fvar (as_fv array_lid)) None a | false |
Pulse.Typing.fst | Pulse.Typing.mk_array_length | val mk_array_length (a arr: term) : term | val mk_array_length (a arr: term) : term | let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 430,
"start_col": 0,
"start_line": 427
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.array_length_lid"
] | [] | false | false | false | true | false | let mk_array_length (a arr: term) : term =
| let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | false |
Pulse.Typing.fst | Pulse.Typing.mk_szv | val mk_szv (n: term) : term | val mk_szv (n: term) : term | let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 452,
"start_col": 0,
"start_line": 450
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.szv_lid"
] | [] | false | false | false | true | false | let mk_szv (n: term) : term =
| let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | false |
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_array_body_pre | val comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop | val comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop | let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 85,
"end_line": 457,
"start_col": 0,
"start_line": 454
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pre: Pulse.Syntax.Base.vprop ->
a: Pulse.Syntax.Base.term ->
arr: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
len: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Typing.mk_array_pts_to",
"Pulse.Typing.mk_seq_create",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.mk_szv",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Typing.mk_eq2",
"Pulse.Typing.tm_nat",
"Pulse.Typing.mk_array_length"
] | [] | false | false | false | true | false | let comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop =
| tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) | false |
Pulse.Typing.fst | Pulse.Typing.comp_rewrite | val comp_rewrite (p q: vprop) : comp | val comp_rewrite (p q: vprop) : comp | let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 481,
"start_col": 0,
"start_line": 475
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Pulse.Syntax.Base.vprop -> q: Pulse.Syntax.Base.vprop -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_rewrite (p q: vprop) : comp =
| C_STGhost ({ u = u0; res = tm_unit; pre = p; post = q }) | false |
Hacl.Spec.K256.Scalar.Lemmas.fst | Hacl.Spec.K256.Scalar.Lemmas.lemma_b_pow2_256_plus_a_modq | val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q) | val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q) | let lemma_b_pow2_256_plus_a_modq a b =
calc (==) {
(b * (pow2 256 - S.q) + a) % S.q;
(==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
(==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
} | {
"file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 340,
"start_col": 0,
"start_line": 333
} | module Hacl.Spec.K256.Scalar.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Hacl.Spec.K256.Scalar
module S = Spec.K256
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val qas_nat4_is_qas_nat (f:qelem_lseq) :
Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4;
SD.bn_eval_unfold_i f 3;
SD.bn_eval_unfold_i f 2;
SD.bn_eval_unfold_i f 1;
SD.bn_eval0 f
val qas_nat4_inj (f1 f2:qelem4) : Lemma
(requires qas_nat4 f1 = qas_nat4 f2)
(ensures
(let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 =
let (a0,a1,a2,a3) = f1 in
let (b0,b1,b2,b3) = f2 in
let bf1 = create4 a0 a1 a2 a3 in
let bf2 = create4 b0 b1 b2 b3 in
qas_nat4_is_qas_nat bf1;
qas_nat4_is_qas_nat bf2;
SD.bn_eval_inj 4 bf1 bf2
#push-options "--ifuel 1"
val is_qelem_zero_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0))
let is_qelem_zero_vartime4_lemma f = ()
val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 +
0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 +
0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
#pop-options
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 ->
Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f =
let (f0, f1, f2, f3) = f in
assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192);
assert (v f0 + v f1 * pow2 64 < pow2 128);
if v f2 = 0 && v f3 = 0 then ()
else begin
Math.Lemmas.pow2_lt_compat 192 128;
assert (pow2 128 <= qas_nat4 f) end
val lemma_check_overflow: b:nat{b < pow2 256} ->
Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in
if b < S.q then begin
assert (pow2 256 + b - S.q < pow2 256);
assert (pow2 256 - S.q <= pow2 256 + b - S.q);
assert_norm (0 < pow2 256 - S.q);
Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256);
assert (overflow = 0) end
else begin
assert (pow2 256 <= pow2 256 + b - S.q);
Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256);
Math.Lemmas.cancel_mul_div 1 (pow2 256);
assert (1 <= overflow);
assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q);
assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1);
Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256);
assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1);
assert (overflow <= 1) end
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat ->
Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256);
Math.Lemmas.small_div r (pow2 256)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma
(requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q)
(ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q);
let mask = u64 0 -. c in
let out1 = map2 (BB.mask_select mask) out a in
assert (v mask = (if v c = 0 then 0 else ones_v U64));
BB.lseq_mask_select_lemma out a mask;
assert (out1 == (if v c = 0 then a else out));
SD.bn_eval_bound a 4;
SD.bn_eval_bound out 4;
lemma_check_overflow (SD.bn_v a);
lemma_get_carry_from_bn_add (SD.bn_v out) (v c);
assert (v c = (if SD.bn_v a < S.q then 0 else 1));
if SD.bn_v a < S.q then begin
assert (SD.bn_v out1 == SD.bn_v a);
Math.Lemmas.small_mod (SD.bn_v a) S.q end
else begin
assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256);
Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1;
assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q);
Math.Lemmas.small_mod (SD.bn_v out1) S.q end
val mod_short_lseq_lemma: a:qelem_lseq ->
Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma a =
let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in
let tmp = create4 t0 t1 t2 t3 in
let c, out = SB.bn_add a tmp in
SB.bn_add_lemma a tmp;
assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp);
qas_nat4_is_qas_nat tmp;
assert (SD.bn_v tmp == pow2 256 - S.q);
mod_short_lseq_lemma_aux a out c
val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len ->
Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q))
let mul_pow2_256_minus_q_lemma len resLen a =
let t0 = u64 0x402da1732fc9bebf in
let t1 = u64 0x4551231950b75fc4 in
assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128);
let t01 = create2 t0 t1 in
SD.bn_eval_unfold_i t01 2;
SD.bn_eval_unfold_i t01 1;
SD.bn_eval0 t01;
assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128);
let m0 = SB.bn_mul a t01 in // a * t01
SB.bn_mul_lemma a t01;
assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01);
let m10 = create resLen (u64 0) in
let m1 = update_sub m10 2 len a in // a * t2 * pow2 128
SD.bn_update_sub_eval m10 a 2;
assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128);
SD.bn_eval_zeroes #U64 resLen resLen;
eq_intro (sub m10 2 len) (create len (u64 0));
SD.bn_eval_zeroes #U64 len len;
assert (SD.bn_v m1 = SD.bn_v a * pow2 128);
let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C
SB.bn_add_lemma m1 m0;
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01);
Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01);
assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} ->
Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p);
assert_norm (pow2 256 - S.q < pow2 129);
Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129);
Math.Lemmas.pow2_plus p 129
val carry_is_zero (c d e a:nat) : Lemma
(requires
a < pow2 d /\ e < pow2 d /\
c * pow2 d + e = a)
(ensures c = 0)
let carry_is_zero c d e a = ()
val mul_pow2_256_minus_q_add_lemma:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma
(requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma len resLen d a e =
let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C
mul_pow2_256_minus_q_lemma len resLen a;
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129));
Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129);
assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen));
SD.bn_eval_bound m resLen;
assert (SD.bn_v m < pow2 (64 * resLen));
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q));
assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q));
let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C
SB.bn_add_lemma m e;
assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e);
SD.bn_eval_bound e 4;
assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)
val mul_pow2_256_minus_q_add_lemma_carry_is_zero:
len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat
-> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma
(requires
SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\
256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen)
(ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in
v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\
v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256))
let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f =
let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in
mul_pow2_256_minus_q_add_lemma len resLen d a e;
let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in
assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m);
assert (rhs_m < pow2 (d + 129) + pow2 256);
Math.Lemmas.pow2_le_compat f 256;
Math.Lemmas.pow2_le_compat f (d + 129);
Math.Lemmas.pow2_double_sum f;
assert (rhs_m < pow2 (f + 1));
Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1);
carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m;
assert (v c0 = 0 /\ SD.bn_v m = rhs_m)
val lemma_m_bound: m:lseq uint64 7 -> Lemma
(requires SD.bn_v m < pow2 385 + pow2 256)
(ensures SD.bn_v (sub m 4 3) < pow2 130)
let lemma_m_bound m =
Math.Lemmas.pow2_lt_compat 385 256;
Math.Lemmas.pow2_double_sum 385;
SD.bn_eval_split_i m 4;
assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256;
assert (SD.bn_v (sub m 4 3) < pow2 130)
val lemma_p_bound: p:lseq uint64 5 -> Lemma
(requires SD.bn_v p < pow2 259 + pow2 256)
(ensures SD.bn_v (sub p 4 1) < pow2 4)
let lemma_p_bound p =
Math.Lemmas.pow2_lt_compat 259 256;
Math.Lemmas.pow2_double_sum 259;
SD.bn_eval_split_i p 4;
assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1));
Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256);
Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256;
assert (SD.bn_v (sub p 4 1) < pow2 4)
val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma
(let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
v c0 = 0 /\ SD.bn_v m = rhs_a /\
v c1 = 0 /\ SD.bn_v p = rhs_m /\
v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256)
let mod_lseq_before_final_lemma_aux a =
let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C
let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in
SD.bn_eval_bound (sub a 4 4) 4;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385;
assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256);
let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C
let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in
lemma_m_bound m;
mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259;
assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256);
let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C
lemma_p_bound p;
mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4);
let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in
assert (v c2 * pow2 256 + SD.bn_v r = rhs_p);
assert (rhs_p < pow2 133 + pow2 256)
val lemma_b_pow2_256_plus_a_modq (a b: nat) :
Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.K256.Scalar.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.UInt32.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.K256.Scalar.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"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": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(b * Prims.pow2 256 + a) % Spec.K256.PointOps.q =
(b * (Prims.pow2 256 - Spec.K256.PointOps.q) + a) % Spec.K256.PointOps.q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.K256.PointOps.q",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.distributivity_sub_right",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_sub"
] | [] | false | false | true | false | false | let lemma_b_pow2_256_plus_a_modq a b =
| calc ( == ) {
(b * (pow2 256 - S.q) + a) % S.q;
( == ) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q }
(b * pow2 256 - b * S.q + a) % S.q;
( == ) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b }
(b * pow2 256 + a) % S.q;
} | false |
Pulse.Typing.fst | Pulse.Typing.mk_seq | val mk_seq (u: universe) (a: term) : term | val mk_seq (u: universe) (a: term) : term | let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 461,
"start_col": 0,
"start_line": 459
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u564: Pulse.Syntax.Base.universe -> a: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.seq_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_seq (u: universe) (a: term) : term =
| let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | false |
Pulse.Typing.fst | Pulse.Typing.ghost_typing | val ghost_typing : g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.typ -> Type0 | let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 500,
"start_col": 0,
"start_line": 499
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.typ -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.typing",
"FStar.Stubs.TypeChecker.Core.E_Ghost"
] | [] | false | false | false | true | true | let ghost_typing (g: env) (e: term) (t: typ) =
| typing g e T.E_Ghost t | false |
|
Pulse.Typing.fst | Pulse.Typing.mk_seq_create | val mk_seq_create (u: universe) (a len v: term) : term | val mk_seq_create (u: universe) (a len v: term) : term | let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 448,
"start_col": 0,
"start_line": 444
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u548: Pulse.Syntax.Base.universe ->
a: Pulse.Syntax.Base.term ->
len: Pulse.Syntax.Base.term ->
v: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.seq_create_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_seq_create (u: universe) (a len v: term) : term =
| let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v | false |
Pulse.Typing.fst | Pulse.Typing.typing | val typing : g: Pulse.Typing.Env.env ->
e: Pulse.Syntax.Base.term ->
eff: FStar.Stubs.TypeChecker.Core.tot_or_ghost ->
t: Pulse.Syntax.Base.term
-> Type0 | let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 494,
"start_col": 0,
"start_line": 493
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
e: Pulse.Syntax.Base.term ->
eff: FStar.Stubs.TypeChecker.Core.tot_or_ghost ->
t: Pulse.Syntax.Base.term
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"Pulse.Typing.my_erased",
"FStar.Reflection.Typing.typing",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.Types.typ"
] | [] | false | false | false | true | true | let typing (g: env) (e: term) (eff: T.tot_or_ghost) (t: term) =
| my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) | false |
|
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_body_post | val comp_withlocal_body_post (post init_t r: term) : term | val comp_withlocal_body_post (post init_t r: term) : term | let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 86,
"end_line": 413,
"start_col": 0,
"start_line": 412
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | post: Pulse.Syntax.Base.term -> init_t: Pulse.Syntax.Base.term -> r: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Pure.u0",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.mk_pts_to",
"Pulse.Syntax.Pure.null_bvar"
] | [] | false | false | false | true | false | let comp_withlocal_body_post (post init_t r: term) : term =
| tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | false |
Pulse.Typing.fst | Pulse.Typing.tot_typing | val tot_typing : g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.term -> Type0 | let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 497,
"start_col": 0,
"start_line": 496
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.term -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.typing",
"FStar.Stubs.TypeChecker.Core.E_Total"
] | [] | false | false | false | true | true | let tot_typing (g: env) (e t: term) =
| typing g e T.E_Total t | false |
|
Pulse.Typing.fst | Pulse.Typing.tm_prop | val tm_prop : Pulse.Syntax.Base.term | let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 81,
"end_line": 42,
"start_col": 0,
"start_line": 42
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.with_range",
"Pulse.Syntax.Base.Tm_FStar",
"FStar.Reflection.Typing.tm_prop",
"FStar.Range.range_0"
] | [] | false | false | false | true | false | let tm_prop =
| with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | false |
|
Pulse.Typing.fst | Pulse.Typing.universe_of | val universe_of : g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> u642: Pulse.Syntax.Base.universe -> Type0 | let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 28,
"end_line": 511,
"start_col": 0,
"start_line": 510
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> u642: Pulse.Syntax.Base.universe -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.universe",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Pure.tm_type"
] | [] | false | false | false | true | true | let universe_of (g: env) (t: term) (u: universe) =
| tot_typing g t (tm_type u) | false |
|
Pulse.Typing.fst | Pulse.Typing.non_informative_t | val non_informative_t : g: Pulse.Typing.Env.env -> u647: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Type0 | let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 514,
"start_col": 0,
"start_line": 513
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> u647: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Prims.dtuple2",
"Pulse.Typing.tot_typing",
"Pulse.Typing.non_informative_witness_t"
] | [] | false | false | false | true | true | let non_informative_t (g: env) (u: universe) (t: term) =
| w: term & tot_typing g w (non_informative_witness_t u t) | false |
|
Pulse.Typing.fst | Pulse.Typing.comp_return | val comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp | val comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp | let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 103,
"start_col": 0,
"start_line": 85
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Pulse.Syntax.Base.ctag ->
use_eq: Prims.bool ->
u66: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term ->
post: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.var
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ctag",
"Prims.bool",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Neutral",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Naming.close_term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Typing.mk_eq2",
"Pulse.Syntax.Pure.null_var"
] | [] | false | false | false | true | false | let comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp =
| let post_maybe_eq =
if use_eq
then
let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post
in
match c with
| STT -> C_ST ({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq })
| STT_Atomic ->
C_STAtomic tm_emp_inames
Neutral
({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq })
| STT_Ghost -> C_STGhost ({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq }) | false |
Pulse.Typing.fst | Pulse.Typing.all_fresh | val all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) | val all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) | let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 93,
"end_line": 128,
"start_col": 0,
"start_line": 125
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> xs: Prims.list Pulse.Typing.Env.binding -> Prims.Tot Prims.prop | Prims.Tot | [
"total",
""
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Typing.Env.binding",
"Prims.l_True",
"Prims.l_and",
"Pulse.Typing.freshv",
"FStar.Pervasives.Native.fst",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.all_fresh",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.ppname_default",
"FStar.Pervasives.Native.snd",
"Prims.prop"
] | [
"recursion"
] | false | false | false | true | true | let rec all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) =
| match xs with
| [] -> True
| x :: xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | false |
Pulse.Typing.fst | Pulse.Typing.tm_inames_subset_typing | val tm_inames_subset_typing (g: env) (inames1 inames2: term)
: tot_typing g (tm_inames_subset inames1 inames2) tm_prop | val tm_inames_subset_typing (g: env) (inames1 inames2: term)
: tot_typing g (tm_inames_subset inames1 inames2) tm_prop | let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic() | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 544,
"start_col": 0,
"start_line": 540
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> inames1: Pulse.Syntax.Base.term -> inames2: Pulse.Syntax.Base.term
-> Pulse.Typing.tot_typing g (Pulse.Typing.tm_inames_subset inames1 inames2) Pulse.Typing.tm_prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.RuntimeUtils.magic",
"Pulse.Typing.tot_typing",
"Pulse.Typing.tm_inames_subset",
"Pulse.Typing.tm_prop"
] | [] | false | false | false | false | false | let tm_inames_subset_typing (g: env) (inames1 inames2: term)
: tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
| RU.magic () | false |
Hacl.Spec.Chacha20.Equiv.fst | Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k1 | val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_last_lemma w blocksize (u8 0) rem b_v j; mod_div_lt blocksize j rem }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
(==) { }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
} | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 898,
"start_col": 0,
"start_line": 871
} | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain
#set-options "--using_facts_from '* -FStar.Seq.Properties.slice_slice'"
val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"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": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
hi_fv: Lib.IntTypes.size_nat{w * hi_fv + w <= Lib.IntTypes.max_size_t} ->
rem: Prims.nat{rem < w * Hacl.Spec.Chacha20.Equiv.blocksize} ->
b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 rem ->
j:
Prims.nat
{ (rem / Hacl.Spec.Chacha20.Equiv.blocksize) * Hacl.Spec.Chacha20.Equiv.blocksize <= j /\
j < rem }
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
let g_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last st_v0 in
let f = Spec.Chacha20.chacha20_encrypt_block st0 in
let g = Spec.Chacha20.chacha20_encrypt_last st0 in
Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k w
Hacl.Spec.Chacha20.Equiv.blocksize
hi_fv
f
g
g_v
rem
b_v
j)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size_nat",
"FStar.Mul.op_Star",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.l_and",
"Prims.op_Division",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.Sequence.div_mul_lt",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i",
"Prims.squash",
"Lib.Sequence.mod_div_lt",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma",
"Lib.IntTypes.u8",
"Lib.IntTypes.int_t",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.Sequence.Lemmas.get_last_s",
"Lib.Sequence.Lemmas.get_block_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.int",
"Spec.Chacha20.counter",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Chacha20.size_block",
"Spec.Chacha20.chacha20_encrypt_last",
"Spec.Chacha20.block",
"Spec.Chacha20.chacha20_encrypt_block",
"Prims.op_Multiply",
"Hacl.Spec.Chacha20.Vec.size_block",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last",
"Hacl.Spec.Chacha20.Vec.blocks",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_init"
] | [] | false | false | true | false | false | let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j =
| let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc ( == ) {
Seq.index (g_v hi_fv rem b_v) j;
( == ) { (encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j;
div_mul_lt blocksize j w) }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
( == ) { (update_sub_get_last_lemma w blocksize (u8 0) rem b_v j;
mod_div_lt blocksize j rem) }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
( == ) { () }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
} | false |
Pulse.Typing.fst | Pulse.Typing.push_bindings | val push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) | val push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) | let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 133,
"start_col": 0,
"start_line": 130
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> bs: Prims.list Pulse.Typing.Env.binding {Pulse.Typing.all_fresh g bs}
-> Prims.Tot (g': Pulse.Typing.Env.env{Pulse.Typing.Env.env_extends g' g}) | Prims.Tot | [
"total",
""
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Typing.Env.binding",
"Pulse.Typing.all_fresh",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.push_bindings",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Typing.Env.env_extends"
] | [
"recursion"
] | false | false | false | false | false | let rec push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) =
| match bs with
| [] -> g
| (x, t) :: bs -> push_bindings (push_binding g x ppname_default t) bs | false |
Pulse.Typing.fst | Pulse.Typing.join_obs | val join_obs (o1 o2: observability) : observability | val join_obs (o1 o2: observability) : observability | let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 244,
"start_col": 0,
"start_line": 238
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | o1: Pulse.Syntax.Base.observability -> o2: Pulse.Syntax.Base.observability
-> Pulse.Syntax.Base.observability | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.observability",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.Observable",
"Pulse.Syntax.Base.Unobservable"
] | [] | false | false | false | true | false | let join_obs (o1 o2: observability) : observability =
| match o1, o2 with
| Neutral, o | o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable | false |
Pulse.Typing.fst | Pulse.Typing.tr_bindings | val tr_bindings : x: Prims.list (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ)
-> Prims.list FStar.Stubs.Reflection.V2.Data.binding | let tr_bindings = L.map tr_binding | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 672,
"start_col": 0,
"start_line": 672
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.list (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ)
-> Prims.list FStar.Stubs.Reflection.V2.Data.binding | Prims.Tot | [
"total"
] | [] | [
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"FStar.Stubs.Reflection.V2.Data.binding",
"Pulse.Typing.tr_binding"
] | [] | false | false | false | true | false | let tr_bindings =
| L.map tr_binding | false |
|
Pulse.Typing.fst | Pulse.Typing.prop_validity | val prop_validity : g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> Type0 | let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 547,
"start_col": 0,
"start_line": 546
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic() | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Stubs.Tactics.V2.Builtins.prop_validity_token",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term"
] | [] | false | false | false | true | true | let prop_validity (g: env) (t: term) =
| FTB.prop_validity_token (elab_env g) (elab_term t) | false |
|
Pulse.Typing.fst | Pulse.Typing.comp_typing_u | val comp_typing_u : e: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 76,
"end_line": 705,
"start_col": 0,
"start_line": 705
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.comp_typing",
"Pulse.Syntax.Base.universe_of_comp"
] | [] | false | false | false | true | true | let comp_typing_u (e: env) (c: comp_st) =
| comp_typing e c (universe_of_comp c) | false |
|
Pulse.Typing.fst | Pulse.Typing.non_informative | val non_informative : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp -> Type0 | let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c)) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 720,
"start_col": 0,
"start_line": 719
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.comp",
"Pulse.Typing.my_erased",
"FStar.Reflection.Typing.non_informative",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_comp"
] | [] | false | false | false | true | true | let non_informative (g: env) (c: comp) =
| my_erased (RT.non_informative (elab_env g) (elab_comp c)) | false |
|
Pulse.Typing.fst | Pulse.Typing.bind_comp_pre | val bind_comp_pre (x: var) (c1 c2: comp_st) : prop | val bind_comp_pre (x: var) (c1 c2: comp_st) : prop | let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 268,
"start_col": 0,
"start_line": 264
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.var -> c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.open_term",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_pre",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Syntax.Naming.freevars",
"Pulse.Typing.bind_comp_compatible",
"Prims.prop"
] | [] | false | false | false | true | true | let bind_comp_pre (x: var) (c1 c2: comp_st) : prop =
| open_term (comp_post c1) x == comp_pre c2 /\ (~(x `Set.mem` (freevars (comp_post c2)))) /\
bind_comp_compatible c1 c2 | false |
Pulse.Typing.fst | Pulse.Typing.add_frame | val add_frame (s: comp_st) (frame: term) : comp_st | val add_frame (s: comp_st) (frame: term) : comp_st | let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 227,
"start_col": 0,
"start_line": 218
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Pulse.Syntax.Base.comp_st -> frame: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp_st | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.observability",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post"
] | [] | false | false | false | true | false | let add_frame (s: comp_st) (frame: term) : comp_st =
| let add_frame_s (s: st_comp) : st_comp =
{ s with pre = tm_star s.pre frame; post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s) | false |
Pulse.Typing.fst | Pulse.Typing.subtyping_token | val subtyping_token : g: Pulse.Typing.Env.env -> t1: Pulse.Syntax.Base.term -> t2: Pulse.Syntax.Base.term -> Type0 | let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 62,
"end_line": 708,
"start_col": 0,
"start_line": 707
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t1: Pulse.Syntax.Base.term -> t2: Pulse.Syntax.Base.term -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Stubs.Tactics.Types.subtyping_token",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term"
] | [] | false | false | false | true | true | let subtyping_token g t1 t2 =
| T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) | false |
|
Pulse.Typing.fst | Pulse.Typing.st_equiv_pre | val st_equiv_pre (c1 c2: comp_st) : prop | val st_equiv_pre (c1 c2: comp_st) : prop | let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False) | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 289,
"start_col": 0,
"start_line": 280
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.comp_u",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.st_comp",
"Prims.l_True",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.observability",
"Prims.l_False",
"Prims.logical",
"Prims.prop"
] | [] | false | false | false | true | true | let st_equiv_pre (c1 c2: comp_st) : prop =
| comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ -> True
| _, _ -> False) | false |
Pulse.Typing.fst | Pulse.Typing.bind_comp_out | val bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st | val bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st | let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 278,
"start_col": 0,
"start_line": 271
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c1: Pulse.Syntax.Base.comp_st ->
c2: Pulse.Syntax.Base.comp_st{Pulse.Typing.bind_comp_compatible c1 c2}
-> Pulse.Syntax.Base.comp_st | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.bind_comp_compatible",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.observability",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Typing.join_obs",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.comp_post"
] | [] | false | false | false | false | false | let bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st =
| let s:st_comp = { u = comp_u c2; res = comp_res c2; pre = comp_pre c1; post = comp_post c2 } in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s | false |
Pulse.Typing.fst | Pulse.Typing.eff_of_ctag | val eff_of_ctag : _: Pulse.Syntax.Base.ctag -> FStar.Stubs.TypeChecker.Core.tot_or_ghost | let eff_of_ctag = function
| STT_Ghost -> T.E_Ghost
| _ -> T.E_Total | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 728,
"start_col": 0,
"start_line": 726
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
let inv_disjointness (inv_p inames inv:term) =
let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in
tm_fstar g inv.range | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Pulse.Syntax.Base.ctag -> FStar.Stubs.TypeChecker.Core.tot_or_ghost | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ctag",
"FStar.Stubs.TypeChecker.Core.E_Ghost",
"FStar.Stubs.TypeChecker.Core.E_Total",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost"
] | [] | false | false | false | true | false | let eff_of_ctag =
| function
| STT_Ghost -> T.E_Ghost
| _ -> T.E_Total | false |
|
Pulse.Typing.fst | Pulse.Typing.effect_annot_typing | val effect_annot_typing : g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.effect_annot -> Type0 | let effect_annot_typing (g:env) (e:effect_annot) =
match e with
| EffectAnnotAtomic { opens } ->
tot_typing g opens tm_inames
| _ ->
unit | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 8,
"end_line": 1135,
"start_col": 0,
"start_line": 1130
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
let inv_disjointness (inv_p inames inv:term) =
let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in
tm_fstar g inv.range
let eff_of_ctag = function
| STT_Ghost -> T.E_Ghost
| _ -> T.E_Total
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
typing g e (eff_of_ctag c) t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_BindFn:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp { C_Tot? c1 } ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
st_typing g e1 c1 ->
u:Ghost.erased universe ->
tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
comp_typing_u g c2 ->
st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing_u g c) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
my_erased (comp_typing_u g c) ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_Sub :
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_sub g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing_u g cL ->
comp_typing_u g cR ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
binder_ppname:ppname ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
binder_ppname:ppname ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
| T_Unreachable:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
prop_validity g (tm_fstar (`False) FStar.Range.range_0) ->
st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s)
(* This limits the body to be atomic, rather than also allowing unobservable *)
| T_WithInv:
g:env ->
inv_tm : term ->
inv_vprop : vprop ->
inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost
inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) ->
body : st_term ->
c : comp_st { C_STAtomic? c } ->
body_typing : st_typing g body (add_frame c inv_vprop) ->
inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) ->
st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None}))
(add_iname_at_least_unobservable c inv_vprop inv_tm)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
let fresh_wrt (x:var) (g:env) (vars:_) =
None? (lookup g x) /\ ~(x `Set.mem` vars) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.effect_annot -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.effect_annot",
"Pulse.Syntax.Base.term",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_inames",
"Prims.unit"
] | [] | false | false | false | true | true | let effect_annot_typing (g: env) (e: effect_annot) =
| match e with
| EffectAnnotAtomic { opens = opens } -> tot_typing g opens tm_inames
| _ -> unit | false |
|
Pulse.Typing.fst | Pulse.Typing.post_hint_for_env | val post_hint_for_env : g: Pulse.Typing.Env.env -> Type0 | let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p } | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 73,
"end_line": 1163,
"start_col": 0,
"start_line": 1163
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
let inv_disjointness (inv_p inames inv:term) =
let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in
tm_fstar g inv.range
let eff_of_ctag = function
| STT_Ghost -> T.E_Ghost
| _ -> T.E_Total
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
typing g e (eff_of_ctag c) t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_BindFn:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp { C_Tot? c1 } ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
st_typing g e1 c1 ->
u:Ghost.erased universe ->
tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
comp_typing_u g c2 ->
st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing_u g c) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
my_erased (comp_typing_u g c) ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_Sub :
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_sub g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing_u g cL ->
comp_typing_u g cR ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
binder_ppname:ppname ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
binder_ppname:ppname ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
| T_Unreachable:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
prop_validity g (tm_fstar (`False) FStar.Range.range_0) ->
st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s)
(* This limits the body to be atomic, rather than also allowing unobservable *)
| T_WithInv:
g:env ->
inv_tm : term ->
inv_vprop : vprop ->
inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost
inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) ->
body : st_term ->
c : comp_st { C_STAtomic? c } ->
body_typing : st_typing g body (add_frame c inv_vprop) ->
inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) ->
st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None}))
(add_iname_at_least_unobservable c inv_vprop inv_tm)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
let fresh_wrt (x:var) (g:env) (vars:_) =
None? (lookup g x) /\ ~(x `Set.mem` vars)
let effect_annot_typing (g:env) (e:effect_annot) =
match e with
| EffectAnnotAtomic { opens } ->
tot_typing g opens tm_inames
| _ ->
unit
noeq
type post_hint_t = {
g:env;
effect_annot:effect_annot;
effect_annot_typing:effect_annot_typing g effect_annot;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
x:(x:var { fresh_wrt x g (freevars post) });
post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.post_hint_t",
"Pulse.Typing.post_hint_for_env_p"
] | [] | false | false | false | true | true | let post_hint_for_env (g: env) =
| p: post_hint_t{post_hint_for_env_p g p} | false |
|
Pulse.Typing.fst | Pulse.Typing.comp_par | val comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp | val comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp | let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 407,
"start_col": 0,
"start_line": 394
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
cL: Pulse.Syntax.Base.comp{C_ST? cL} ->
cR: Pulse.Syntax.Base.comp{C_ST? cR} ->
x: Pulse.Syntax.Base.var
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Typing.mk_tuple2",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.term",
"Pulse.Typing.par_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.comp_u"
] | [] | false | false | false | false | false | let comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp =
| let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST
({ u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post = post }) | false |
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_array_body | val comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp | val comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp | let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 473,
"start_col": 0,
"start_line": 466
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
arr: Pulse.Syntax.Base.var ->
a: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
len: Pulse.Syntax.Base.term ->
c: Pulse.Syntax.Base.comp{C_ST? c}
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Typing.comp_withlocal_array_body_pre",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Typing.comp_withlocal_array_body_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Pure.null_var"
] | [] | false | false | false | false | false | let comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp =
| let arr = null_var arr in
C_ST
({
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}) | false |
Pulse.Typing.fst | Pulse.Typing.comp_withlocal_body | val comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp | val comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp | let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
} | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 422,
"start_col": 0,
"start_line": 415
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Pulse.Syntax.Base.var ->
init_t: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
c: Pulse.Syntax.Base.comp{C_ST? c}
-> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Typing.comp_withlocal_body_pre",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Typing.comp_withlocal_body_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Pure.null_var"
] | [] | false | false | false | false | false | let comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp =
| let r = null_var r in
C_ST
({
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}) | false |
Pulse.Typing.fst | Pulse.Typing.comp_admit | val comp_admit (c: ctag) (s: st_comp) : comp | val comp_admit (c: ctag) (s: st_comp) : comp | let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 28,
"end_line": 487,
"start_col": 0,
"start_line": 483
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.ctag -> s: Pulse.Syntax.Base.st_comp -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Neutral",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.comp"
] | [] | false | false | false | true | false | let comp_admit (c: ctag) (s: st_comp) : comp =
| match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s | false |
Hacl.Spec.Curve25519.Finv.fst | Hacl.Spec.Curve25519.Finv.finv0 | val finv0: inp:elem ->
Pure (tuple2 elem elem)
(requires True)
(ensures fun (a, t0) ->
a == pow inp 11 /\
t0 == pow inp pow_t0) | val finv0: inp:elem ->
Pure (tuple2 elem elem)
(requires True)
(ensures fun (a, t0) ->
a == pow inp 11 /\
t0 == pow inp pow_t0) | let finv0 i =
(* 2 *) let a = fsquare_times i 1 in
assert (a == pow i 2);
(* 8 *) let t0 = fsquare_times a 2 in
assert (t0 == pow a 4);
lemma_pow_mul i 2 4;
assert (t0 == pow i 8);
(* 9 *) let b = fmul t0 i in
lemma_pow_one i;
lemma_pow_add i 8 1;
assert (b == pow i 9);
(* 11 *) let a = fmul b a in
lemma_pow_add i 9 2;
assert (a == pow i 11);
(* 22 *) let t0 = fsquare_times a 1 in
lemma_pow_mul i 11 2;
assert (t0 == pow i 22);
(* 2^5 - 2^0 = 31 *) let b = fmul t0 b in
lemma_pow_add i 22 9;
assert (b == pow i 31);
(* 2^10 - 2^5 *) let t0 = fsquare_times b 5 in
lemma_pow_mul i 31 (pow2 5);
assert_norm (31 * pow2 5 = pow2 10 - pow2 5);
assert (t0 == pow i (pow2 10 - pow2 5));
(* 2^10 - 2^0 *) let b = fmul t0 b in
assert_norm (31 = pow2 5 - 1);
lemma_pow_add i (pow2 10 - pow2 5) (pow2 5 - 1);
assert (b == pow i (pow2 10 - 1));
(* 2^20 - 2^10 *) let t0 = fsquare_times b 10 in
lemma_pow_mul i (pow2 10 - 1) (pow2 10);
assert_norm ((pow2 10 - 1) * pow2 10 == pow2 20 - pow2 10);
assert (t0 == pow i (pow2 20 - pow2 10));
(* 2^20 - 2^0 *) let c = fmul t0 b in
lemma_pow_add i (pow2 20 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 20 - pow2 10 + pow2 10 - 1 = pow2 20 - 1);
assert (c == pow i (pow2 20 - 1));
(* 2^40 - 2^20 *) let t0 = fsquare_times c 20 in
lemma_pow_mul i (pow2 20 - 1) (pow2 20);
assert_norm ((pow2 20 - 1) * pow2 20 = pow2 40 - pow2 20);
assert (t0 == pow i (pow2 40 - pow2 20));
(* 2^40 - 2^0 *) let t0 = fmul t0 c in
lemma_pow_add i (pow2 40 -pow2 20) (pow2 20 - 1);
assert_norm (pow2 40 - pow2 20 + pow2 20 - 1 = pow2 40 - 1);
assert (t0 == pow i (pow2 40 - 1));
(* 2^50 - 2^10 *) let t0 = fsquare_times t0 10 in
lemma_pow_mul i (pow2 40 - 1) (pow2 10);
assert_norm ((pow2 40 - 1) * pow2 10 = pow2 50 - pow2 10);
assert (t0 == pow i (pow2 50 - pow2 10));
(* 2^50 - 2^0 *) let b = fmul t0 b in
lemma_pow_add i (pow2 50 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 50 - pow2 10 + pow2 10 - 1 = pow2 50 - 1);
assert (b == pow i (pow2 50 - 1));
(* 2^100 - 2^50 *) let t0 = fsquare_times b 50 in
lemma_pow_mul i (pow2 50 - 1) (pow2 50);
assert_norm ((pow2 50 - 1) * pow2 50 = pow2 100 - pow2 50);
assert (t0 == pow i (pow2 100 - pow2 50));
(* 2^100 - 2^0 *) let c = fmul t0 b in
lemma_pow_add i (pow2 100 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 100 - pow2 50 + pow2 50 - 1 = pow2 100 - 1);
assert (c == pow i (pow2 100 - 1));
(* 2^200 - 2^100 *) let t0 = fsquare_times c 100 in
lemma_pow_mul i (pow2 100 - 1) (pow2 100);
assert_norm ((pow2 100 - 1) * pow2 100 = pow2 200 - pow2 100);
assert (t0 == pow i (pow2 200 - pow2 100));
(* 2^200 - 2^0 *) let t0 = fmul t0 c in
lemma_pow_add i (pow2 200 - pow2 100) (pow2 100 - 1);
assert_norm (pow2 200 - pow2 100 + pow2 100 - 1 = pow2 200 - 1);
assert (t0 == pow i (pow2 200 - 1));
(* 2^250 - 2^50 *) let t0 = fsquare_times t0 50 in
lemma_pow_mul i (pow2 200 - 1) (pow2 50);
assert_norm ((pow2 200 - 1) * pow2 50 = pow2 250 - pow2 50);
assert (t0 == pow i (pow2 250 - pow2 50));
(* 2^250 - 2^0 *) let t0 = fmul t0 b in
lemma_pow_add i (pow2 250 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 250 - pow2 50 + pow2 50 - 1 = pow2 250 - 1);
assert (t0 == pow i (pow2 250 - 1));
(* 2^255 - 2^5 *) let t0 = fsquare_times t0 5 in
lemma_pow_mul i (pow2 250 - 1) (pow2 5);
assert_norm ((pow2 250 - 1) * pow2 5 = pow2 255 - pow2 5);
assert (t0 == pow i (pow2 255 - pow2 5));
a, t0 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 162,
"start_col": 0,
"start_line": 82
} | module Hacl.Spec.Curve25519.Finv
open FStar.Mul
open Spec.Curve25519
module M = Lib.NatMod
module LE = Lib.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let fsqr x = fmul x x
let pow = fpow
let cm_prime = M.mk_nat_mod_comm_monoid prime
val lemma_pow_mod_is_pow_cm : x:elem -> b:nat -> Lemma (pow x b = LE.pow cm_prime x b)
let lemma_pow_mod_is_pow_cm x b =
M.lemma_pow_nat_mod_is_pow #prime x b;
M.lemma_pow_mod #prime x b
val lemma_pow_one: x:elem -> Lemma (x == pow x 1)
let lemma_pow_one x =
lemma_pow_mod_is_pow_cm x 1;
LE.lemma_pow1 cm_prime x
val lemma_pow_add: x:elem -> n:nat -> m:nat ->
Lemma (fmul (pow x n) (pow x m) == pow x (n + m))
let lemma_pow_add x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm x m;
LE.lemma_pow_add cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n + m)
val lemma_pow_mul: x:elem -> n:nat -> m:nat ->
Lemma (pow (pow x n) m == pow x (n * m))
let lemma_pow_mul x n m =
lemma_pow_mod_is_pow_cm x n;
lemma_pow_mod_is_pow_cm (pow x n) m;
LE.lemma_pow_mul cm_prime x n m;
lemma_pow_mod_is_pow_cm x (n * m)
val lemma_pow_double: a:elem -> b:nat ->
Lemma (pow (a *% a) b == pow a (b + b))
let lemma_pow_double a b =
lemma_pow_mod_is_pow_cm (a *% a) b;
LE.lemma_pow_double cm_prime a b;
lemma_pow_mod_is_pow_cm a (b + b)
val fsquare_times: inp:elem -> n:pos -> out:elem{out == pow inp (pow2 n)}
let fsquare_times inp n =
let out = fsqr inp in
lemma_pow_one inp;
lemma_pow_add inp 1 1;
assert_norm (pow2 1 = 2);
assert (out == pow inp (pow2 1));
let out =
Lib.LoopCombinators.repeati_inductive #elem (n - 1)
(fun i out -> out == pow inp (pow2 (i + 1)))
(fun i out ->
assert (out == pow inp (pow2 (i + 1)));
let res = fsqr out in
calc (==) {
fmul out out;
(==) { lemma_pow_add inp (pow2 (i + 1)) (pow2 (i + 1)) }
pow inp (pow2 (i + 1) + pow2 (i + 1));
(==) { Math.Lemmas.pow2_double_sum (i + 1) }
pow inp (pow2 (i + 2));
};
res) out in
assert (out == pow inp (pow2 n));
out
let pow_t0:nat =
assert_norm (pow2 255 - pow2 5 > 0);
pow2 255 - pow2 5
val finv0: inp:elem ->
Pure (tuple2 elem elem)
(requires True)
(ensures fun (a, t0) ->
a == pow inp 11 /\ | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.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.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | inp: Spec.Curve25519.elem -> Prims.Pure (Spec.Curve25519.elem * Spec.Curve25519.elem) | Prims.Pure | [] | [] | [
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Curve25519.Finv.pow",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Hacl.Spec.Curve25519.Finv.lemma_pow_mul",
"Hacl.Spec.Curve25519.Finv.fsquare_times",
"Prims.op_Addition",
"Hacl.Spec.Curve25519.Finv.lemma_pow_add",
"Spec.Curve25519.fmul",
"Hacl.Spec.Curve25519.Finv.lemma_pow_one",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let finv0 i =
| let a = fsquare_times i 1 in
assert (a == pow i 2);
let t0 = fsquare_times a 2 in
assert (t0 == pow a 4);
lemma_pow_mul i 2 4;
assert (t0 == pow i 8);
let b = fmul t0 i in
lemma_pow_one i;
lemma_pow_add i 8 1;
assert (b == pow i 9);
let a = fmul b a in
lemma_pow_add i 9 2;
assert (a == pow i 11);
let t0 = fsquare_times a 1 in
lemma_pow_mul i 11 2;
assert (t0 == pow i 22);
let b = fmul t0 b in
lemma_pow_add i 22 9;
assert (b == pow i 31);
let t0 = fsquare_times b 5 in
lemma_pow_mul i 31 (pow2 5);
assert_norm (31 * pow2 5 = pow2 10 - pow2 5);
assert (t0 == pow i (pow2 10 - pow2 5));
let b = fmul t0 b in
assert_norm (31 = pow2 5 - 1);
lemma_pow_add i (pow2 10 - pow2 5) (pow2 5 - 1);
assert (b == pow i (pow2 10 - 1));
let t0 = fsquare_times b 10 in
lemma_pow_mul i (pow2 10 - 1) (pow2 10);
assert_norm ((pow2 10 - 1) * pow2 10 == pow2 20 - pow2 10);
assert (t0 == pow i (pow2 20 - pow2 10));
let c = fmul t0 b in
lemma_pow_add i (pow2 20 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 20 - pow2 10 + pow2 10 - 1 = pow2 20 - 1);
assert (c == pow i (pow2 20 - 1));
let t0 = fsquare_times c 20 in
lemma_pow_mul i (pow2 20 - 1) (pow2 20);
assert_norm ((pow2 20 - 1) * pow2 20 = pow2 40 - pow2 20);
assert (t0 == pow i (pow2 40 - pow2 20));
let t0 = fmul t0 c in
lemma_pow_add i (pow2 40 - pow2 20) (pow2 20 - 1);
assert_norm (pow2 40 - pow2 20 + pow2 20 - 1 = pow2 40 - 1);
assert (t0 == pow i (pow2 40 - 1));
let t0 = fsquare_times t0 10 in
lemma_pow_mul i (pow2 40 - 1) (pow2 10);
assert_norm ((pow2 40 - 1) * pow2 10 = pow2 50 - pow2 10);
assert (t0 == pow i (pow2 50 - pow2 10));
let b = fmul t0 b in
lemma_pow_add i (pow2 50 - pow2 10) (pow2 10 - 1);
assert_norm (pow2 50 - pow2 10 + pow2 10 - 1 = pow2 50 - 1);
assert (b == pow i (pow2 50 - 1));
let t0 = fsquare_times b 50 in
lemma_pow_mul i (pow2 50 - 1) (pow2 50);
assert_norm ((pow2 50 - 1) * pow2 50 = pow2 100 - pow2 50);
assert (t0 == pow i (pow2 100 - pow2 50));
let c = fmul t0 b in
lemma_pow_add i (pow2 100 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 100 - pow2 50 + pow2 50 - 1 = pow2 100 - 1);
assert (c == pow i (pow2 100 - 1));
let t0 = fsquare_times c 100 in
lemma_pow_mul i (pow2 100 - 1) (pow2 100);
assert_norm ((pow2 100 - 1) * pow2 100 = pow2 200 - pow2 100);
assert (t0 == pow i (pow2 200 - pow2 100));
let t0 = fmul t0 c in
lemma_pow_add i (pow2 200 - pow2 100) (pow2 100 - 1);
assert_norm (pow2 200 - pow2 100 + pow2 100 - 1 = pow2 200 - 1);
assert (t0 == pow i (pow2 200 - 1));
let t0 = fsquare_times t0 50 in
lemma_pow_mul i (pow2 200 - 1) (pow2 50);
assert_norm ((pow2 200 - 1) * pow2 50 = pow2 250 - pow2 50);
assert (t0 == pow i (pow2 250 - pow2 50));
let t0 = fmul t0 b in
lemma_pow_add i (pow2 250 - pow2 50) (pow2 50 - 1);
assert_norm (pow2 250 - pow2 50 + pow2 50 - 1 = pow2 250 - 1);
assert (t0 == pow i (pow2 250 - 1));
let t0 = fsquare_times t0 5 in
lemma_pow_mul i (pow2 250 - 1) (pow2 5);
assert_norm ((pow2 250 - 1) * pow2 5 = pow2 255 - pow2 5);
assert (t0 == pow i (pow2 255 - pow2 5));
a, t0 | false |
Pulse.Typing.fst | Pulse.Typing.post_hint_for_env_p | val post_hint_for_env_p : g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_t -> Prims.logical | let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 1154,
"start_col": 0,
"start_line": 1154
} | (*
Copyright 2023 Microsoft Research
Licensed 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 Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames Neutral
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
| VE_Fa:
g:env ->
x:var { None? (lookup g x) } ->
u:universe ->
b:binder ->
t0:term { ~(x `Set.mem` freevars t0 ) } ->
t1:term { ~(x `Set.mem` freevars t1 ) } ->
vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) ->
vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s)
| C_STGhost s -> C_STGhost (add_frame_s s)
let add_inv (s:comp_st) (v:vprop)
: comp_st
= add_frame s v
let at_most_one_observable o1 o2 =
match o1, o2 with
| Observable, Observable -> false
| _ -> true
let join_obs (o1 o2:observability) : observability =
match o1, o2 with
| Neutral, o
| o, Neutral -> o
| Observable, _ -> Observable
| _, Observable -> Observable
| Unobservable, Unobservable -> Unobservable
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) =
let add_inv_tm (inames:term) =
tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm))
inames.range
in
let C_STAtomic inames obs s = s in
C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_ST _, C_ST _
| C_STGhost _, C_STGhost _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ at_most_one_observable obs1 obs2
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost _, C_STGhost _ -> C_STGhost s
| C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ ->
C_STAtomic inames (join_obs obs1 obs2) s
| C_ST _, C_ST _ -> C_ST s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ ->
inames1 == inames2 /\ obs1 == obs2
| C_STGhost _, C_STGhost _ ->
True
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost {
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost {
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = mk_binder_ppname t x
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost {
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term =
tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
// let mk_array_is_full (a:term) (arr:term) : term =
// let t = tm_fvar (as_fv array_is_full_lid) in
// let t = tm_pureapp t (Some Implicit) a in
// tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames Neutral s
| STT_Ghost -> C_STGhost s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
// TODO: move
let tm_join_inames (inames1 inames2 : term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else
if eq_tm inames2 tm_emp_inames then inames1 else
if eq_tm inames1 inames2 then inames1 else
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset (inames1 inames2 : term) : term =
let inames1 = elab_term inames1 in
let inames2 = elab_term inames2 in
let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in
let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in
with_range (Tm_FStar (R.mk_e_app join [inames1; inames2]))
(T.range_of_term inames1)
let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop =
(* Need to add the typing hypothesis for `inames_subset` to
the env and a precondition that the inames have type Pulse.Lib.Core.inames in g,
which the caller should get from an inversion lemma *)
RU.magic()
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
| ST_TotEquiv :
g:env ->
t1:term ->
t2:term ->
u:_ ->
universe_of g t1 u ->
Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) ->
st_equiv g (C_Tot t1) (C_Tot t2)
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
[@@ no_auto_projectors]
noeq
type st_sub : env -> comp -> comp -> Type =
| STS_Refl :
g:env ->
c:comp ->
st_sub g c c
| STS_Trans :
g:env ->
c1:comp ->
c2:comp ->
c3:comp ->
st_sub g c1 c2 ->
st_sub g c2 c3 ->
st_sub g c1 c3
| STS_AtomicInvs :
g:env ->
stc:st_comp ->
is1:term ->
is2:term ->
obs1:observability ->
obs2:observability { sub_observability obs1 obs2 } ->
prop_validity g (tm_inames_subset is1 is2) ->
st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here!
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_Observability:
g:env ->
c:comp_st{C_STAtomic? c } ->
o2:observability { sub_observability (C_STAtomic?.obs c) o2 } ->
lift_comp g
(C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c))
(C_STAtomic (comp_inames c) o2 (st_comp_of_comp c))
| Lift_Ghost_Neutral:
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c))
| Lift_Neutral_Ghost:
g:env ->
c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } ->
lift_comp g c (C_STGhost (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) (universe_of_comp (C_ST st))
| CT_STAtomic :
g:env ->
inames:term ->
obs:observability ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st))
| CT_STGhost :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st))
let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
let inv_disjointness (inv_p inames inv:term) =
let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in
tm_fstar g inv.range
let eff_of_ctag = function
| STT_Ghost -> T.E_Ghost
| _ -> T.E_Total
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
typing g e (eff_of_ctag c) t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_BindFn:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp { C_Tot? c1 } ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
st_typing g e1 c1 ->
u:Ghost.erased universe ->
tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
comp_typing_u g c2 ->
st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing_u g c) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
my_erased (comp_typing_u g c) ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_Sub :
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_sub g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing_u g cL ->
comp_typing_u g cR ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
binder_ppname:ppname ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
binder_ppname:ppname ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing_u g c ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
| T_Unreachable:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
prop_validity g (tm_fstar (`False) FStar.Range.range_0) ->
st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s)
(* This limits the body to be atomic, rather than also allowing unobservable *)
| T_WithInv:
g:env ->
inv_tm : term ->
inv_vprop : vprop ->
inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost
inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) ->
body : st_term ->
c : comp_st { C_STAtomic? c } ->
body_typing : st_typing g body (add_frame c inv_vprop) ->
inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) ->
st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None}))
(add_iname_at_least_unobservable c inv_vprop inv_tm)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
let fresh_wrt (x:var) (g:env) (vars:_) =
None? (lookup g x) /\ ~(x `Set.mem` vars)
let effect_annot_typing (g:env) (e:effect_annot) =
match e with
| EffectAnnotAtomic { opens } ->
tot_typing g opens tm_inames
| _ ->
unit
noeq
type post_hint_t = {
g:env;
effect_annot:effect_annot;
effect_annot_typing:effect_annot_typing g effect_annot;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
x:(x:var { fresh_wrt x g (freevars post) });
post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_t -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.post_hint_t",
"Pulse.Typing.Env.env_extends",
"Pulse.Typing.__proj__Mkpost_hint_t__item__g",
"Prims.logical"
] | [] | false | false | false | true | true | let post_hint_for_env_p (g: env) (p: post_hint_t) =
| g `env_extends` p.g | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.