effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val inv_mixColumn (c: size_nat{c < 4}) (state: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state | val inv_mixColumn (c: size_nat{c < 4}) (state: block) : Tot block
let inv_mixColumn (c: size_nat{c < 4}) (state: block) : Tot block = | false | null | false | let i0 = 4 * c in
let s0 = state.[ i0 ] in
let s1 = state.[ i0 + 1 ] in
let s2 = state.[ i0 + 2 ] in
let s3 = state.[ i0 + 3 ] in
let state = state.[ i0 ] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[ i0 + 1 ] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[ i0 + 2 ] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[ i0 + 3 ] <- inv_mix4 s3 s0 s1 s2 in
state | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Spec.AES.block",
"Lib.Sequence.lseq",
"Spec.AES.elem",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Prims.op_Addition",
"Spec.AES.inv_mix4",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"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.Sequence.op_String_Access",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val inv_mixColumn (c: size_nat{c < 4}) (state: block) : Tot block | [] | Spec.AES.inv_mixColumn | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | c: Lib.IntTypes.size_nat{c < 4} -> state: Spec.AES.block -> Spec.AES.block | {
"end_col": 7,
"end_line": 142,
"start_col": 65,
"start_line": 132
} |
Prims.Tot | val aes_ctr_key_block (v: variant) (k: aes_xkey v) (n: lbytes 12) (c: size_nat) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_ctr_key_block (v:variant) (k:aes_xkey v) (n:lbytes 12) (c:size_nat) : Tot block =
let ctrby = nat_to_bytes_be 4 c in
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) 12 (fun i b -> b.[i] <- n.[i]) input in
let input = repeati #(lbytes 16) 4 (fun i b -> b.[12+i] <- (Seq.index ctrby i)) input in
aes_encrypt_block v k input | val aes_ctr_key_block (v: variant) (k: aes_xkey v) (n: lbytes 12) (c: size_nat) : Tot block
let aes_ctr_key_block (v: variant) (k: aes_xkey v) (n: lbytes 12) (c: size_nat) : Tot block = | false | null | false | let ctrby = nat_to_bytes_be 4 c in
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) 12 (fun i b -> b.[ i ] <- n.[ i ]) input in
let input = repeati #(lbytes 16) 4 (fun i b -> b.[ 12 + i ] <- (Seq.index ctrby i)) input in
aes_encrypt_block v k input | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_xkey",
"Lib.ByteSequence.lbytes",
"Lib.IntTypes.size_nat",
"Spec.AES.aes_encrypt_block",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.LoopCombinators.repeati",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.uint_t",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Access",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.u8",
"Lib.Sequence.seq",
"Lib.Sequence.length",
"Prims.l_or",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.ByteSequence.nat_from_intseq_be",
"Lib.ByteSequence.nat_to_bytes_be",
"Spec.AES.block"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex
let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state
let aes_encrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_enc_rounds v k state in
let state = aes_enc_last kn state in
state
let aes_dec_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_dec (sub key (16*i) 16)) state
let aes_decrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_ctr_key_block (v: variant) (k: aes_xkey v) (n: lbytes 12) (c: size_nat) : Tot block | [] | Spec.AES.aes_ctr_key_block | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
v: Spec.AES.variant ->
k: Spec.AES.aes_xkey v ->
n: Lib.ByteSequence.lbytes 12 ->
c: Lib.IntTypes.size_nat
-> Spec.AES.block | {
"end_col": 29,
"end_line": 334,
"start_col": 89,
"start_line": 329
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let zero = to_elem 0 | let zero = | false | null | false | to_elem 0 | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.to_elem"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8 | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val zero : Spec.GaloisField.felem Spec.AES.gf8 | [] | Spec.AES.zero | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.GaloisField.felem Spec.AES.gf8 | {
"end_col": 20,
"end_line": 19,
"start_col": 11,
"start_line": 19
} |
|
Prims.Tot | val aes128_key_expansion (key: lbytes 16) : Tot (lseq elem (11 * 16)) | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex | val aes128_key_expansion (key: lbytes 16) : Tot (lseq elem (11 * 16))
let aes128_key_expansion (key: lbytes 16) : Tot (lseq elem (11 * 16)) = | false | null | false | let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16))
10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i + 1)) p in
let n = key_expansion_step p a in
update_sub kex ((i + 1) * 16) 16 n)
key_ex
in
key_ex | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Lib.ByteSequence.lbytes",
"Lib.Sequence.lseq",
"Spec.AES.elem",
"Prims.op_Multiply",
"Lib.LoopCombinators.repeati",
"FStar.Mul.op_Star",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.update_sub",
"Prims.op_Addition",
"Spec.AES.block",
"Spec.AES.key_expansion_step",
"Spec.AES.keygen_assist0",
"Spec.AES.rcon_spec",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.uint_t",
"FStar.Seq.Base.create",
"Spec.AES.to_elem",
"Prims.l_imp",
"Lib.Sequence.create"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes128_key_expansion (key: lbytes 16) : Tot (lseq elem (11 * 16)) | [] | Spec.AES.aes128_key_expansion | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | key: Lib.ByteSequence.lbytes 16 -> Lib.Sequence.lseq Spec.AES.elem (11 * 16) | {
"end_col": 8,
"end_line": 261,
"start_col": 70,
"start_line": 250
} |
Prims.Tot | val subBytes (state: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subBytes (state:block) : Tot block =
map sub_byte state | val subBytes (state: block) : Tot block
let subBytes (state: block) : Tot block = | false | null | false | map sub_byte state | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.block",
"Lib.Sequence.map",
"Spec.AES.elem",
"Spec.AES.sub_byte"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subBytes (state: block) : Tot block | [] | Spec.AES.subBytes | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | state: Spec.AES.block -> Spec.AES.block | {
"end_col": 20,
"end_line": 68,
"start_col": 2,
"start_line": 68
} |
Prims.Tot | val rcon_spec: i:size_nat -> Tot elem | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1) | val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i = | false | null | false | if i = 0 then to_elem 0x8d else if i = 1 then to_elem 1 else two `fmul` (rcon_spec (i - 1)) | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_nat",
"Prims.op_Equality",
"Prims.int",
"Spec.AES.to_elem",
"Prims.bool",
"Spec.GaloisField.fmul",
"Spec.AES.gf8",
"Spec.AES.two",
"Spec.AES.rcon_spec",
"Prims.op_Subtraction",
"Spec.AES.elem"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rcon_spec: i:size_nat -> Tot elem | [
"recursion"
] | Spec.AES.rcon_spec | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Lib.IntTypes.size_nat -> Spec.AES.elem | {
"end_col": 35,
"end_line": 193,
"start_col": 2,
"start_line": 191
} |
Prims.Tot | val aes_ctr_add_counter (v: variant) (st: aes_ctr_state v) (incr: size_nat) : Tot (aes_ctr_state v) | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_ctr_add_counter (v:variant) (st:aes_ctr_state v) (incr:size_nat) : Tot (aes_ctr_state v) =
let n = nat_from_bytes_be st.block in
let n' = (n + incr) % pow2 128 in
let nblock' = nat_to_bytes_be 16 n' in
{st with block = nblock'} | val aes_ctr_add_counter (v: variant) (st: aes_ctr_state v) (incr: size_nat) : Tot (aes_ctr_state v)
let aes_ctr_add_counter (v: variant) (st: aes_ctr_state v) (incr: size_nat) : Tot (aes_ctr_state v) = | false | null | false | let n = nat_from_bytes_be st.block in
let n' = (n + incr) % pow2 128 in
let nblock' = nat_to_bytes_be 16 n' in
{ st with block = nblock' } | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_ctr_state",
"Lib.IntTypes.size_nat",
"Spec.AES.Mkaes_ctr_state",
"Spec.AES.__proj__Mkaes_ctr_state__item__key_ex",
"Lib.Sequence.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.ByteSequence.nat_from_intseq_be",
"Lib.ByteSequence.nat_to_bytes_be",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"Spec.AES.__proj__Mkaes_ctr_state__item__block",
"Lib.ByteSequence.nat_from_bytes_be"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex
let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state
let aes_encrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_enc_rounds v k state in
let state = aes_enc_last kn state in
state
let aes_dec_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_dec (sub key (16*i) 16)) state
let aes_decrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state
let aes_ctr_key_block (v:variant) (k:aes_xkey v) (n:lbytes 12) (c:size_nat) : Tot block =
let ctrby = nat_to_bytes_be 4 c in
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) 12 (fun i b -> b.[i] <- n.[i]) input in
let input = repeati #(lbytes 16) 4 (fun i b -> b.[12+i] <- (Seq.index ctrby i)) input in
aes_encrypt_block v k input
noeq type aes_ctr_state (v:variant) = {
key_ex: lbytes ((num_rounds v + 1) * 16);
block: lbytes 16;
} | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_ctr_add_counter (v: variant) (st: aes_ctr_state v) (incr: size_nat) : Tot (aes_ctr_state v) | [] | Spec.AES.aes_ctr_add_counter | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | v: Spec.AES.variant -> st: Spec.AES.aes_ctr_state v -> incr: Lib.IntTypes.size_nat
-> Spec.AES.aes_ctr_state v | {
"end_col": 27,
"end_line": 345,
"start_col": 98,
"start_line": 341
} |
Prims.Tot | val aes_ctr_key_block0 (v: variant) (k: aes_key v) (n_len: size_nat{n_len <= 16}) (n: lbytes n_len)
: Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_ctr_key_block0 (v:variant) (k:aes_key v) (n_len:size_nat{n_len <= 16}) (n:lbytes n_len) : Tot block =
let st = aes_ctr_init v k n_len n 0 in
aes_ctr_current_key_block v st | val aes_ctr_key_block0 (v: variant) (k: aes_key v) (n_len: size_nat{n_len <= 16}) (n: lbytes n_len)
: Tot block
let aes_ctr_key_block0 (v: variant) (k: aes_key v) (n_len: size_nat{n_len <= 16}) (n: lbytes n_len)
: Tot block = | false | null | false | let st = aes_ctr_init v k n_len n 0 in
aes_ctr_current_key_block v st | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_key",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.ByteSequence.lbytes",
"Spec.AES.aes_ctr_current_key_block",
"Spec.AES.aes_ctr_state",
"Spec.AES.aes_ctr_init",
"Spec.AES.block"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex
let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state
let aes_encrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_enc_rounds v k state in
let state = aes_enc_last kn state in
state
let aes_dec_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_dec (sub key (16*i) 16)) state
let aes_decrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state
let aes_ctr_key_block (v:variant) (k:aes_xkey v) (n:lbytes 12) (c:size_nat) : Tot block =
let ctrby = nat_to_bytes_be 4 c in
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) 12 (fun i b -> b.[i] <- n.[i]) input in
let input = repeati #(lbytes 16) 4 (fun i b -> b.[12+i] <- (Seq.index ctrby i)) input in
aes_encrypt_block v k input
noeq type aes_ctr_state (v:variant) = {
key_ex: lbytes ((num_rounds v + 1) * 16);
block: lbytes 16;
}
let aes_ctr_add_counter (v:variant) (st:aes_ctr_state v) (incr:size_nat) : Tot (aes_ctr_state v) =
let n = nat_from_bytes_be st.block in
let n' = (n + incr) % pow2 128 in
let nblock' = nat_to_bytes_be 16 n' in
{st with block = nblock'}
let aes_ctr_init (v:variant) (k:aes_key v) (n_len:size_nat{n_len <= 16}) (n:lbytes n_len) (c0:size_nat) : Tot (aes_ctr_state v) =
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) n_len (fun i b -> b.[i] <- n.[i]) input in
let key_ex = aes_key_expansion v k in
let st0 = { key_ex = key_ex; block = input} in
aes_ctr_add_counter v st0 c0
let aes_ctr_current_key_block (v:variant) (st:aes_ctr_state v) : Tot block =
aes_encrypt_block v st.key_ex st.block | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_ctr_key_block0 (v: variant) (k: aes_key v) (n_len: size_nat{n_len <= 16}) (n: lbytes n_len)
: Tot block | [] | Spec.AES.aes_ctr_key_block0 | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
v: Spec.AES.variant ->
k: Spec.AES.aes_key v ->
n_len: Lib.IntTypes.size_nat{n_len <= 16} ->
n: Lib.ByteSequence.lbytes n_len
-> Spec.AES.block | {
"end_col": 32,
"end_line": 359,
"start_col": 109,
"start_line": 357
} |
Prims.Tot | val aes_enc_rounds (v: variant) (key: aes_ikey v) (state: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state | val aes_enc_rounds (v: variant) (key: aes_ikey v) (state: block) : Tot block
let aes_enc_rounds (v: variant) (key: aes_ikey v) (state: block) : Tot block = | false | null | false | repeati (num_rounds v - 1) (fun i -> aes_enc (sub key (16 * i) 16)) state | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_ikey",
"Spec.AES.block",
"Lib.LoopCombinators.repeati",
"Prims.op_Subtraction",
"Spec.AES.num_rounds",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Spec.AES.aes_enc",
"Lib.Sequence.sub",
"Spec.AES.elem",
"FStar.Mul.op_Star"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_enc_rounds (v: variant) (key: aes_ikey v) (state: block) : Tot block | [] | Spec.AES.aes_enc_rounds | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | v: Spec.AES.variant -> key: Spec.AES.aes_ikey v -> state: Spec.AES.block -> Spec.AES.block | {
"end_col": 71,
"end_line": 304,
"start_col": 2,
"start_line": 304
} |
Prims.Tot | val keygen_assist1 (s: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st | val keygen_assist1 (s: block) : Tot block
let keygen_assist1 (s: block) : Tot block = | false | null | false | let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.block",
"Lib.Sequence.lseq",
"Spec.AES.elem",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"Spec.AES.aes_keygen_assist",
"Spec.AES.zero"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val keygen_assist1 (s: block) : Tot block | [] | Spec.AES.keygen_assist1 | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Spec.AES.block -> Spec.AES.block | {
"end_col": 4,
"end_line": 240,
"start_col": 42,
"start_line": 236
} |
Prims.Tot | val rcon_seq:lseq elem 11 | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l | val rcon_seq:lseq elem 11
let rcon_seq:lseq elem 11 = | false | null | false | assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Lib.Sequence.of_list",
"Spec.AES.elem",
"Spec.AES.rcon_l",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
] | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rcon_seq:lseq elem 11 | [] | Spec.AES.rcon_seq | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Lib.Sequence.lseq Spec.AES.elem 11 | {
"end_col": 16,
"end_line": 203,
"start_col": 2,
"start_line": 202
} |
Prims.Tot | val aes_decrypt_block (v: variant) (key: aes_xkey v) (input: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_decrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state | val aes_decrypt_block (v: variant) (key: aes_xkey v) (input: block) : Tot block
let aes_decrypt_block (v: variant) (key: aes_xkey v) (input: block) : Tot block = | false | null | false | let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v - 1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_xkey",
"Spec.AES.block",
"Spec.AES.aes_dec_last",
"Spec.AES.aes_dec_rounds",
"Spec.AES.addRoundKey",
"Lib.Sequence.lseq",
"Spec.AES.elem",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.op_Addition",
"Spec.AES.num_rounds",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Lib.Sequence.slice"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex
let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state
let aes_encrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_enc_rounds v k state in
let state = aes_enc_last kn state in
state
let aes_dec_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_dec (sub key (16*i) 16)) state | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_decrypt_block (v: variant) (key: aes_xkey v) (input: block) : Tot block | [] | Spec.AES.aes_decrypt_block | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | v: Spec.AES.variant -> key: Spec.AES.aes_xkey v -> input: Spec.AES.block -> Spec.AES.block | {
"end_col": 7,
"end_line": 327,
"start_col": 78,
"start_line": 319
} |
Prims.Tot | val rotate_word (w: word) : Tot word | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]] | val rotate_word (w: word) : Tot word
let rotate_word (w: word) : Tot word = | false | null | false | of_list [w.[ 1 ]; w.[ 2 ]; w.[ 3 ]; w.[ 0 ]] | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.word",
"Lib.Sequence.of_list",
"Spec.AES.elem",
"Prims.Cons",
"Lib.Sequence.op_String_Access",
"Prims.Nil"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rotate_word (w: word) : Tot word | [] | Spec.AES.rotate_word | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | w: Spec.AES.word -> Spec.AES.word | {
"end_col": 38,
"end_line": 184,
"start_col": 2,
"start_line": 184
} |
Prims.Tot | val aes256_key_expansion (key: lbytes 32) : Tot (lseq elem (15 * 16)) | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14 | val aes256_key_expansion (key: lbytes 32) : Tot (lseq elem (15 * 16))
let aes256_key_expansion (key: lbytes 32) : Tot (lseq elem (15 * 16)) = | false | null | false | let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16))
6
(fun i key_ex ->
let p0 = sub key_ex ((2 * i) * 16) 16 in
let p1 = sub key_ex (((2 * i) + 1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i + 1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2 * i) + 2) * 16) 16 n0 in
update_sub key_ex (((2 * i) + 3) * 16) 16 n1)
key_ex
in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14 | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Lib.ByteSequence.lbytes",
"Lib.Sequence.update_sub",
"Spec.AES.elem",
"FStar.Mul.op_Star",
"Spec.AES.block",
"Spec.AES.key_expansion_step",
"Spec.AES.keygen_assist0",
"Spec.AES.rcon_spec",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Lib.LoopCombinators.repeati",
"Prims.op_LessThanOrEqual",
"Spec.AES.keygen_assist1",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.uint_t",
"FStar.Seq.Base.create",
"Spec.AES.to_elem",
"Prims.l_imp",
"Lib.Sequence.create"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes256_key_expansion (key: lbytes 32) : Tot (lseq elem (15 * 16)) | [] | Spec.AES.aes256_key_expansion | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | key: Lib.ByteSequence.lbytes 32 -> Lib.Sequence.lseq Spec.AES.elem (15 * 16) | {
"end_col": 36,
"end_line": 282,
"start_col": 70,
"start_line": 263
} |
Prims.Tot | val aes_ctr_encrypt_bytes:
v:variant
-> key:aes_key v
-> n_len:size_nat{n_len <= 16}
-> nonce:lbytes n_len
-> c:size_nat
-> msg:bytes{length msg / 16 + c <= max_size_t} ->
Tot (ciphertext:bytes{length ciphertext == length msg}) | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_ctr_encrypt_bytes v key n_len nonce ctr0 msg =
let st0 = aes_ctr_init v key n_len nonce ctr0 in
aes_ctr_encrypt_stream v st0 msg | val aes_ctr_encrypt_bytes:
v:variant
-> key:aes_key v
-> n_len:size_nat{n_len <= 16}
-> nonce:lbytes n_len
-> c:size_nat
-> msg:bytes{length msg / 16 + c <= max_size_t} ->
Tot (ciphertext:bytes{length ciphertext == length msg})
let aes_ctr_encrypt_bytes v key n_len nonce ctr0 msg = | false | null | false | let st0 = aes_ctr_init v key n_len nonce ctr0 in
aes_ctr_encrypt_stream v st0 msg | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.variant",
"Spec.AES.aes_key",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.ByteSequence.lbytes",
"Lib.ByteSequence.bytes",
"Prims.op_Addition",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.max_size_t",
"Spec.AES.aes_ctr_encrypt_stream",
"Spec.AES.aes_ctr_state",
"Spec.AES.aes_ctr_init",
"Prims.eq2",
"Prims.nat"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100"
let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st
let keygen_assist0 (rcon:elem) (s:block) : Tot block =
let st = aes_keygen_assist rcon s in
let st = update_sub st 8 4 (sub st 12 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let keygen_assist1 (s:block) : Tot block =
let st = aes_keygen_assist zero s in
let st = update_sub st 12 4 (sub st 8 4) in
let st = update_sub st 0 8 (sub st 8 8) in
st
let key_expansion_step (p:block) (assist:block) : Tot block =
let p0 = create 16 (to_elem 0) in
let k = p in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
let k = xor_block k (update_sub p0 4 12 (sub k 0 12)) in
xor_block k assist
let aes128_key_expansion (key:lbytes 16) : Tot (lseq elem (11 * 16)) =
let key_ex = create (11 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 16 key in
let key_ex =
repeati #(lseq elem (11 * 16)) 10
(fun i kex ->
let p = sub kex (i * 16) 16 in
let a = keygen_assist0 (rcon_spec (i+1)) p in
let n = key_expansion_step p a in
update_sub kex ((i+1) * 16) 16 n)
key_ex in
key_ex
let aes256_key_expansion (key:lbytes 32) : Tot (lseq elem (15 * 16)) =
let key_ex = create (15 * 16) (to_elem 0) in
let key_ex = update_sub key_ex 0 32 key in
let key_ex =
repeati #(lseq elem (15 * 16)) 6
(fun i key_ex ->
let p0 = sub key_ex (2 * i * 16) 16 in
let p1 = sub key_ex (((2*i)+1) * 16) 16 in
let a0 = keygen_assist0 (rcon_spec (i+1)) p1 in
let n0 = key_expansion_step p0 a0 in
let a1 = keygen_assist1 n0 in
let n1 = key_expansion_step p1 a1 in
let key_ex = update_sub key_ex (((2*i)+2) * 16) 16 n0 in
update_sub key_ex (((2*i)+3) * 16) 16 n1)
key_ex in
let p0 = sub key_ex (12 * 16) 16 in
let p1 = sub key_ex (13 * 16) 16 in
let a14 = keygen_assist0 (rcon_spec 7) p1 in
let n14 = key_expansion_step p0 a14 in
update_sub key_ex (14 * 16) 16 n14
let aes_key_expansion (v:variant) (key: aes_key v) : aes_xkey v =
match v with
| AES128 -> aes128_key_expansion key
| AES256 -> aes256_key_expansion key
let aes_dec_key_expansion (v:variant) (key:aes_key v): aes_xkey v =
let ekey_ex : aes_xkey v = aes_key_expansion v key in
let k0 = sub ekey_ex 0 16 in
let kn = sub ekey_ex ((num_rounds v) * 16) 16 in
let _,key_ex = generate_blocks 16 (num_rounds v + 1) (num_rounds v + 1)
(fun i -> unit)
(fun i a ->
let b = sub ekey_ex ((num_rounds v - i) * 16) 16 in
if i = 0 then (), b
else if i < num_rounds v then
(),inv_mixColumns b
else (),b) () in
key_ex
let aes_enc_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_enc (sub key (16*i) 16)) state
let aes_encrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_enc_rounds v k state in
let state = aes_enc_last kn state in
state
let aes_dec_rounds (v:variant) (key:aes_ikey v) (state:block) : Tot block =
repeati (num_rounds v-1) (fun i -> aes_dec (sub key (16*i) 16)) state
let aes_decrypt_block (v:variant) (key:aes_xkey v) (input:block) : Tot block =
let state = input in
let k0 = slice key 0 16 in
let k = sub key 16 ((num_rounds v-1) * 16) in
let kn = sub key (num_rounds v * 16) 16 in
let state = addRoundKey k0 state in
let state = aes_dec_rounds v k state in
let state = aes_dec_last kn state in
state
let aes_ctr_key_block (v:variant) (k:aes_xkey v) (n:lbytes 12) (c:size_nat) : Tot block =
let ctrby = nat_to_bytes_be 4 c in
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) 12 (fun i b -> b.[i] <- n.[i]) input in
let input = repeati #(lbytes 16) 4 (fun i b -> b.[12+i] <- (Seq.index ctrby i)) input in
aes_encrypt_block v k input
noeq type aes_ctr_state (v:variant) = {
key_ex: lbytes ((num_rounds v + 1) * 16);
block: lbytes 16;
}
let aes_ctr_add_counter (v:variant) (st:aes_ctr_state v) (incr:size_nat) : Tot (aes_ctr_state v) =
let n = nat_from_bytes_be st.block in
let n' = (n + incr) % pow2 128 in
let nblock' = nat_to_bytes_be 16 n' in
{st with block = nblock'}
let aes_ctr_init (v:variant) (k:aes_key v) (n_len:size_nat{n_len <= 16}) (n:lbytes n_len) (c0:size_nat) : Tot (aes_ctr_state v) =
let input = create 16 (u8 0) in
let input = repeati #(lbytes 16) n_len (fun i b -> b.[i] <- n.[i]) input in
let key_ex = aes_key_expansion v k in
let st0 = { key_ex = key_ex; block = input} in
aes_ctr_add_counter v st0 c0
let aes_ctr_current_key_block (v:variant) (st:aes_ctr_state v) : Tot block =
aes_encrypt_block v st.key_ex st.block
let aes_ctr_key_block0 (v:variant) (k:aes_key v) (n_len:size_nat{n_len <= 16}) (n:lbytes n_len) : Tot block =
let st = aes_ctr_init v k n_len n 0 in
aes_ctr_current_key_block v st
let aes_ctr_key_block1 (v:variant) (k:aes_key v) (n_len:size_nat{n_len <= 16}) (n:lbytes n_len) : Tot block =
let st = aes_ctr_init v k n_len n 1 in
aes_ctr_current_key_block v st
let aes_ctr_encrypt_block
(v:variant)
(st0:aes_ctr_state v)
(incr:size_nat)
(b:block) :
Tot block =
let st = aes_ctr_add_counter v st0 incr in
let kb = aes_ctr_current_key_block v st in
map2 (^.) b kb
let aes_ctr_encrypt_last
(v:variant)
(st0:aes_ctr_state v)
(incr:size_nat)
(len:size_nat{len < 16})
(b:lbytes len):
Tot (lbytes len) =
let plain = create 16 (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = aes_ctr_encrypt_block v st0 incr plain in
sub cipher 0 (length b)
val aes_ctr_encrypt_stream:
v:variant
-> st:aes_ctr_state v
-> msg:bytes{length msg / 16 <= max_size_t} ->
Tot (ciphertext:bytes{length ciphertext == length msg})
let aes_ctr_encrypt_stream v st msg =
map_blocks 16 msg
(aes_ctr_encrypt_block v st)
(aes_ctr_encrypt_last v st)
val aes_ctr_encrypt_bytes:
v:variant
-> key:aes_key v
-> n_len:size_nat{n_len <= 16}
-> nonce:lbytes n_len
-> c:size_nat
-> msg:bytes{length msg / 16 + c <= max_size_t} ->
Tot (ciphertext:bytes{length ciphertext == length msg}) | false | false | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_ctr_encrypt_bytes:
v:variant
-> key:aes_key v
-> n_len:size_nat{n_len <= 16}
-> nonce:lbytes n_len
-> c:size_nat
-> msg:bytes{length msg / 16 + c <= max_size_t} ->
Tot (ciphertext:bytes{length ciphertext == length msg}) | [] | Spec.AES.aes_ctr_encrypt_bytes | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
v: Spec.AES.variant ->
key: Spec.AES.aes_key v ->
n_len: Lib.IntTypes.size_nat{n_len <= 16} ->
nonce: Lib.ByteSequence.lbytes n_len ->
c: Lib.IntTypes.size_nat ->
msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg / 16 + c <= Lib.IntTypes.max_size_t}
-> ciphertext: Lib.ByteSequence.bytes{Lib.Sequence.length ciphertext == Lib.Sequence.length msg} | {
"end_col": 34,
"end_line": 412,
"start_col": 54,
"start_line": 410
} |
Prims.Tot | val aes_keygen_assist (rcon: elem) (s: block) : Tot block | [
{
"abbrev": false,
"full_module": "Spec.GaloisField",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"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.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_keygen_assist (rcon:elem) (s:block) : Tot block =
let st = create 16 (to_elem 0) in
let st = st.[0] <- sub_byte s.[4] in
let st = st.[1] <- sub_byte s.[5] in
let st = st.[2] <- sub_byte s.[6] in
let st = st.[3] <- sub_byte s.[7] in
let st = st.[4] <- rcon ^. sub_byte s.[5] in
let st = st.[6] <- sub_byte s.[6] in
let st = st.[6] <- sub_byte s.[7] in
let st = st.[7] <- sub_byte s.[4] in
let st = st.[8] <- sub_byte s.[12] in
let st = st.[9] <- sub_byte s.[13] in
let st = st.[10] <- sub_byte s.[14] in
let st = st.[11] <- sub_byte s.[15] in
let st = st.[12] <- rcon ^. sub_byte s.[13] in
let st = st.[13] <- sub_byte s.[14] in
let st = st.[14] <- sub_byte s.[15] in
let st = st.[15] <- sub_byte s.[12] in
st | val aes_keygen_assist (rcon: elem) (s: block) : Tot block
let aes_keygen_assist (rcon: elem) (s: block) : Tot block = | false | null | false | let st = create 16 (to_elem 0) in
let st = st.[ 0 ] <- sub_byte s.[ 4 ] in
let st = st.[ 1 ] <- sub_byte s.[ 5 ] in
let st = st.[ 2 ] <- sub_byte s.[ 6 ] in
let st = st.[ 3 ] <- sub_byte s.[ 7 ] in
let st = st.[ 4 ] <- rcon ^. sub_byte s.[ 5 ] in
let st = st.[ 6 ] <- sub_byte s.[ 6 ] in
let st = st.[ 6 ] <- sub_byte s.[ 7 ] in
let st = st.[ 7 ] <- sub_byte s.[ 4 ] in
let st = st.[ 8 ] <- sub_byte s.[ 12 ] in
let st = st.[ 9 ] <- sub_byte s.[ 13 ] in
let st = st.[ 10 ] <- sub_byte s.[ 14 ] in
let st = st.[ 11 ] <- sub_byte s.[ 15 ] in
let st = st.[ 12 ] <- rcon ^. sub_byte s.[ 13 ] in
let st = st.[ 13 ] <- sub_byte s.[ 14 ] in
let st = st.[ 14 ] <- sub_byte s.[ 15 ] in
let st = st.[ 15 ] <- sub_byte s.[ 12 ] in
st | {
"checked_file": "Spec.AES.fst.checked",
"dependencies": [
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.fst"
} | [
"total"
] | [
"Spec.AES.elem",
"Spec.AES.block",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Spec.AES.sub_byte",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.Sequence.op_String_Access",
"Spec.AES.op_Hat_Dot",
"FStar.Seq.Base.create",
"Spec.AES.to_elem",
"Lib.Sequence.create"
] | [] | module Spec.AES
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
open Spec.GaloisField
/// Constants and Types
(* GF(8) Field *)
let irred = u8 0x1b
let gf8 = gf U8 irred
let elem = felem gf8
let to_elem = to_felem #gf8
let zero = to_elem 0
let two = to_elem 2
let three = to_elem 3
(* These operations are normalized here to avoid a huge blowup in generate code size *)
let ( <<<. ) x y = normalize_term (rotate_left #U8 #SEC x y)
let ( ^. ) x y = normalize_term (logxor #U8 #SEC x y)
(* Specification of the Rijndael S-Box : *)
type word = lseq elem 4
type block = lseq elem 16
type variant = | AES128 | AES256
let num_rounds (v:variant) =
match v with
| AES128 -> 10
| AES256 -> 14
let key_size (v:variant) =
match v with
| AES128 -> 16
| AES256 -> 32
let aes_key (v:variant) = lbytes (key_size v)
let aes_xkey (v:variant) = lseq elem ((num_rounds v+1) * 16)
let aes_ikey (v:variant) = lseq elem ((num_rounds v-1) * 16)
let sub_byte (input:elem) =
let s = finv input in
s ^.
(s <<<. size 1) ^.
(s <<<. size 2) ^.
(s <<<. size 3) ^.
(s <<<. size 4) ^.
(to_elem 99)
let inv_sub_byte (input:elem) =
let s = input in
let s:elem =
(s <<<. size 1) ^.
(s <<<. size 3) ^.
(s <<<. size 6) ^.
(u8 5)
in
finv s
let subBytes (state:block) : Tot block =
map sub_byte state
let inv_subBytes (state:block) : Tot block =
map inv_sub_byte state
let shiftRow (i:size_nat{i < 4}) (shift:size_nat{i < 4}) (state:block) : Tot block =
let tmp0 = state.[i + (4 * (shift % 4))] in
let tmp1 = state.[i + (4 * ((shift + 1) % 4))] in
let tmp2 = state.[i + (4 * ((shift + 2) % 4))] in
let tmp3 = state.[i + (4 * ((shift + 3) % 4))] in
let state = state.[i] <- tmp0 in
let state = state.[i+4] <- tmp1 in
let state = state.[i+8] <- tmp2 in
let state = state.[i+12] <- tmp3 in
state
let shiftRows (state: block) : Tot block =
let state = shiftRow 1 1 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 3 state in
state
let inv_shiftRows (state: block) : Tot block =
let state = shiftRow 1 3 state in
let state = shiftRow 2 2 state in
let state = shiftRow 3 1 state in
state
let mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(s0 `fmul` two) `fadd`
(s1 `fmul` three) `fadd`
s2 `fadd` s3
let inv_mix4 (s0:elem) (s1:elem) (s2:elem) (s3:elem) : Tot elem =
(*
(s0 `fmul` to_elem 11) `fadd`
(s1 `fmul` to_elem 13) `fadd`
(s2 `fmul` to_elem 9) `fadd`
(s3 `fmul` to_elem 14)
*)
(s0 `fmul` to_elem 14) `fadd`
(s1 `fmul` to_elem 11) `fadd`
(s2 `fmul` to_elem 13) `fadd`
(s3 `fmul` to_elem 9)
let mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- mix4 s3 s0 s1 s2 in
state
let mixColumns (state:block) : Tot block =
let state = mixColumn 0 state in
let state = mixColumn 1 state in
let state = mixColumn 2 state in
let state = mixColumn 3 state in
state
let inv_mixColumn (c:size_nat{c < 4}) (state:block) : Tot block =
let i0 = 4 * c in
let s0 = state.[i0] in
let s1 = state.[i0 + 1] in
let s2 = state.[i0 + 2] in
let s3 = state.[i0 + 3] in
let state = state.[i0] <- inv_mix4 s0 s1 s2 s3 in
let state = state.[i0+1] <- inv_mix4 s1 s2 s3 s0 in
let state = state.[i0+2] <- inv_mix4 s2 s3 s0 s1 in
let state = state.[i0+3] <- inv_mix4 s3 s0 s1 s2 in
state
let inv_mixColumns (state:block) : Tot block =
let state = inv_mixColumn 0 state in
let state = inv_mixColumn 1 state in
let state = inv_mixColumn 2 state in
let state = inv_mixColumn 3 state in
state
let xor_block (b1:block) (b2:block) : Tot block =
map2 (logxor #U8) b1 b2
let addRoundKey (key:block) (state:block) : Tot block =
xor_block state key
let aes_enc (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = mixColumns state in
let state = addRoundKey key state in
state
let aes_enc_last (key:block) (state:block) : Tot block =
let state = subBytes state in
let state = shiftRows state in
let state = addRoundKey key state in
state
let aes_dec (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = inv_mixColumns state in
let state = addRoundKey key state in
state
let aes_dec_last (key:block) (state:block) : Tot block =
let state = inv_subBytes state in
let state = inv_shiftRows state in
let state = addRoundKey key state in
state
let rotate_word (w:word) : Tot word =
of_list [w.[1]; w.[2]; w.[3]; w.[0]]
let sub_word (w:word) : Tot word =
map sub_byte w
val rcon_spec: i:size_nat -> Tot elem
let rec rcon_spec i =
if i = 0 then to_elem 0x8d
else if i = 1 then to_elem 1
else two `fmul` rcon_spec (i - 1)
let rcon_l : list elem = [
to_elem 0x8d; to_elem 0x01; to_elem 0x02; to_elem 0x04;
to_elem 0x08; to_elem 0x10; to_elem 0x20; to_elem 0x40;
to_elem 0x80; to_elem 0x1b; to_elem 0x36
]
let rcon_seq : lseq elem 11 =
assert_norm (List.Tot.length rcon_l == 11);
of_list rcon_l
#reset-options "--z3rlimit 100" | false | true | Spec.AES.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_keygen_assist (rcon: elem) (s: block) : Tot block | [] | Spec.AES.aes_keygen_assist | {
"file_name": "specs/Spec.AES.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | rcon: Spec.AES.elem -> s: Spec.AES.block -> Spec.AES.block | {
"end_col": 4,
"end_line": 228,
"start_col": 57,
"start_line": 207
} |
Prims.Tot | val openBase: openBase_st cs vale_p | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let openBase = hpke_openBase_higher #cs vale_p IAEAD.aead_decrypt_cp128 setupBaseR | val openBase: openBase_st cs vale_p
let openBase = | false | null | false | hpke_openBase_higher #cs vale_p IAEAD.aead_decrypt_cp128 setupBaseR | {
"checked_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_openBase_higher",
"Hacl.HPKE.Curve64_CP128_SHA256.cs",
"Hacl.HPKE.Curve64_CP128_SHA256.vale_p",
"Hacl.HPKE.Interface.AEAD.aead_decrypt_cp128",
"Hacl.HPKE.Curve64_CP128_SHA256.setupBaseR"
] | [] | module Hacl.HPKE.Curve64_CP128_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256
let setupBaseR = hpke_setupBaseR_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64
let sealBase = hpke_sealBase_higher #cs vale_p IAEAD.aead_encrypt_cp128 setupBaseS | false | true | Hacl.HPKE.Curve64_CP128_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val openBase: openBase_st cs vale_p | [] | Hacl.HPKE.Curve64_CP128_SHA256.openBase | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP128_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.openBase_st Hacl.HPKE.Curve64_CP128_SHA256.cs Hacl.HPKE.Curve64_CP128_SHA256.vale_p | {
"end_col": 82,
"end_line": 20,
"start_col": 15,
"start_line": 20
} |
Prims.Tot | val sealBase: sealBase_st cs vale_p | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sealBase = hpke_sealBase_higher #cs vale_p IAEAD.aead_encrypt_cp128 setupBaseS | val sealBase: sealBase_st cs vale_p
let sealBase = | false | null | false | hpke_sealBase_higher #cs vale_p IAEAD.aead_encrypt_cp128 setupBaseS | {
"checked_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_sealBase_higher",
"Hacl.HPKE.Curve64_CP128_SHA256.cs",
"Hacl.HPKE.Curve64_CP128_SHA256.vale_p",
"Hacl.HPKE.Interface.AEAD.aead_encrypt_cp128",
"Hacl.HPKE.Curve64_CP128_SHA256.setupBaseS"
] | [] | module Hacl.HPKE.Curve64_CP128_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256
let setupBaseR = hpke_setupBaseR_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 | false | true | Hacl.HPKE.Curve64_CP128_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sealBase: sealBase_st cs vale_p | [] | Hacl.HPKE.Curve64_CP128_SHA256.sealBase | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP128_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.sealBase_st Hacl.HPKE.Curve64_CP128_SHA256.cs Hacl.HPKE.Curve64_CP128_SHA256.vale_p | {
"end_col": 82,
"end_line": 18,
"start_col": 15,
"start_line": 18
} |
Prims.Tot | val setupBaseS: setupBaseS_st cs vale_p | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseS = hpke_setupBaseS_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256 | val setupBaseS: setupBaseS_st cs vale_p
let setupBaseS = | false | null | false | hpke_setupBaseS_higher #cs
vale_p
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.secret_to_public_c64
IDH.dh_c64
IHK.hkdf_expand256
IHK.hkdf_extract256 | {
"checked_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_setupBaseS_higher",
"Hacl.HPKE.Curve64_CP128_SHA256.cs",
"Hacl.HPKE.Curve64_CP128_SHA256.vale_p",
"Hacl.HPKE.Interface.HKDF.hkdf_expand256",
"Hacl.HPKE.Interface.HKDF.hkdf_extract256",
"Hacl.HPKE.Interface.DH.secret_to_public_c64",
"Hacl.HPKE.Interface.DH.dh_c64"
] | [] | module Hacl.HPKE.Curve64_CP128_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0" | false | true | Hacl.HPKE.Curve64_CP128_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseS: setupBaseS_st cs vale_p | [] | Hacl.HPKE.Curve64_CP128_SHA256.setupBaseS | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP128_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.setupBaseS_st Hacl.HPKE.Curve64_CP128_SHA256.cs Hacl.HPKE.Curve64_CP128_SHA256.vale_p | {
"end_col": 164,
"end_line": 14,
"start_col": 17,
"start_line": 14
} |
Prims.Tot | val setupBaseR: setupBaseR_st cs vale_p | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseR = hpke_setupBaseR_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 | val setupBaseR: setupBaseR_st cs vale_p
let setupBaseR = | false | null | false | hpke_setupBaseR_higher #cs
vale_p
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.dh_c64
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.secret_to_public_c64 | {
"checked_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Curve64_CP128_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_setupBaseR_higher",
"Hacl.HPKE.Curve64_CP128_SHA256.cs",
"Hacl.HPKE.Curve64_CP128_SHA256.vale_p",
"Hacl.HPKE.Interface.HKDF.hkdf_expand256",
"Hacl.HPKE.Interface.HKDF.hkdf_extract256",
"Hacl.HPKE.Interface.DH.dh_c64",
"Hacl.HPKE.Interface.DH.secret_to_public_c64"
] | [] | module Hacl.HPKE.Curve64_CP128_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs vale_p IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c64 IDH.dh_c64 IHK.hkdf_expand256 IHK.hkdf_extract256 | false | true | Hacl.HPKE.Curve64_CP128_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseR: setupBaseR_st cs vale_p | [] | Hacl.HPKE.Curve64_CP128_SHA256.setupBaseR | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP128_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.setupBaseR_st Hacl.HPKE.Curve64_CP128_SHA256.cs Hacl.HPKE.Curve64_CP128_SHA256.vale_p | {
"end_col": 164,
"end_line": 16,
"start_col": 17,
"start_line": 16
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let collect_app = collect_app' [] | let collect_app = | true | null | false | collect_app' [] | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.V1.Formula.collect_app'",
"Prims.Nil",
"FStar.Reflection.V1.Data.argv"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_app : t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Reflection.Types.term * Prims.list FStar.Reflection.V1.Data.argv) | [] | FStar.Reflection.V1.Formula.collect_app | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Reflection.Types.term * Prims.list FStar.Reflection.V1.Data.argv) | {
"end_col": 41,
"end_line": 43,
"start_col": 26,
"start_line": 43
} |
|
FStar.Tactics.Effect.Tac | val bv_to_string (bv: bv) : Tac string | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname) | val bv_to_string (bv: bv) : Tac string
let bv_to_string (bv: bv) : Tac string = | true | null | false | let bvv = inspect_bv bv in
unseal (bvv.bv_ppname) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.bv",
"FStar.Tactics.Unseal.unseal",
"Prims.string",
"FStar.Reflection.V1.Data.__proj__Mkbv_view__item__bv_ppname",
"FStar.Reflection.V1.Data.bv_view",
"Prims.precedes",
"FStar.Reflection.V1.Builtins.inspect_bv"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bv_to_string (bv: bv) : Tac string | [] | FStar.Reflection.V1.Formula.bv_to_string | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | bv: FStar.Reflection.Types.bv -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 26,
"end_line": 30,
"start_col": 49,
"start_line": 28
} |
FStar.Tactics.Effect.Tac | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args) | val collect_app' (args: list argv) (t: term) : Tac (term * list argv)
let rec collect_app' (args: list argv) (t: term) : Tac (term * list argv) = | true | null | false | match inspect_unascribe t with
| Tv_App l r -> collect_app' (r :: args) l
| _ -> (t, args) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Formula.collect_app'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.Mktuple2",
"Prims.b2t",
"FStar.Reflection.V1.Data.notAscription",
"FStar.Reflection.V1.Formula.inspect_unascribe"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term) | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | [
"recursion"
] | FStar.Reflection.V1.Formula.collect_app' | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | args: Prims.list FStar.Reflection.V1.Data.argv -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Reflection.Types.term * Prims.list FStar.Reflection.V1.Data.argv) | {
"end_col": 20,
"end_line": 42,
"start_col": 4,
"start_line": 39
} |
Prims.Tot | val formula_as_term (f: formula) : Tot term | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let formula_as_term (f:formula) : Tot term =
pack_ln (formula_as_term_view f) | val formula_as_term (f: formula) : Tot term
let formula_as_term (f: formula) : Tot term = | false | null | false | pack_ln (formula_as_term_view f) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [
"total"
] | [
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Formula.formula_as_term_view",
"FStar.Reflection.Types.term"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown
// Unsquashing
let term_as_formula (t:term) : Tac formula =
match unsquash_term t with
| None -> F_Unknown
| Some t ->
term_as_formula' t
let term_as_formula_total (t:term) : Tac formula =
term_as_formula' (maybe_unsquash_term t)
let formula_as_term_view (f:formula) : Tot term_view =
let mk_app' tv args = List.Tot.Base.fold_left (fun tv a -> Tv_App (pack_ln tv) a) tv args in
let e = Q_Explicit in
let i = Q_Implicit in
match f with
| True_ -> Tv_FVar (pack_fv true_qn)
| False_ -> Tv_FVar (pack_fv false_qn)
| Comp (Eq None) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(l,e);(r,e)]
| Comp (Eq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(t,i);(l,e);(r,e)]
| Comp (BoolEq None) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(l,e);(r,e)]
| Comp (BoolEq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(t,i);(l,e);(r,e)]
| Comp Lt l r -> mk_app' (Tv_FVar (pack_fv lt_qn)) [(l,e);(r,e)]
| Comp Le l r -> mk_app' (Tv_FVar (pack_fv lte_qn)) [(l,e);(r,e)]
| Comp Gt l r -> mk_app' (Tv_FVar (pack_fv gt_qn)) [(l,e);(r,e)]
| Comp Ge l r -> mk_app' (Tv_FVar (pack_fv gte_qn)) [(l,e);(r,e)]
| And p q -> mk_app' (Tv_FVar (pack_fv and_qn)) [(p,e);(q,e)]
| Or p q -> mk_app' (Tv_FVar (pack_fv or_qn)) [(p,e);(q,e)]
| Implies p q -> mk_app' (Tv_FVar (pack_fv imp_qn)) [(p,e);(q,e)]
| Not p -> mk_app' (Tv_FVar (pack_fv not_qn)) [(p,e)]
| Iff p q -> mk_app' (Tv_FVar (pack_fv iff_qn)) [(p,e);(q,e)]
| Forall b sort t -> Tv_Unknown // TODO: decide on meaning of this
| Exists b sort t -> Tv_Unknown // TODO: ^
| App p q ->
Tv_App p (q, Q_Explicit)
| Name b ->
Tv_Var b
| FV fv ->
Tv_FVar fv
| IntLit i ->
Tv_Const (C_Int i)
| F_Unknown ->
Tv_Unknown | false | true | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val formula_as_term (f: formula) : Tot term | [] | FStar.Reflection.V1.Formula.formula_as_term | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: FStar.Reflection.V1.Formula.formula -> FStar.Reflection.Types.term | {
"end_col": 36,
"end_line": 205,
"start_col": 4,
"start_line": 205
} |
FStar.Tactics.Effect.Tac | val mk_Forall (typ pred: term) : Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | val mk_Forall (typ pred: term) : Tac formula
let mk_Forall (typ pred: term) : Tac formula = | true | null | false | let b = pack_bv ({ bv_ppname = as_ppname "x"; bv_index = 0 }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Formula.Forall",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.Tv_BVar",
"FStar.Reflection.V1.Data.Q_Explicit",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Builtins.pack_bv",
"FStar.Reflection.V1.Data.Mkbv_view",
"FStar.Reflection.V1.Data.as_ppname",
"FStar.Reflection.V1.Formula.formula"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None" | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_Forall (typ pred: term) : Tac formula | [] | FStar.Reflection.V1.Formula.mk_Forall | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | typ: FStar.Reflection.Types.term -> pred: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.V1.Formula.formula | {
"end_col": 74,
"end_line": 71,
"start_col": 56,
"start_line": 68
} |
FStar.Tactics.Effect.Tac | val mk_Exists (typ pred: term) : Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | val mk_Exists (typ pred: term) : Tac formula
let mk_Exists (typ pred: term) : Tac formula = | true | null | false | let b = pack_bv ({ bv_ppname = as_ppname "x"; bv_index = 0 }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Formula.Exists",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.Tv_BVar",
"FStar.Reflection.V1.Data.Q_Explicit",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Builtins.pack_bv",
"FStar.Reflection.V1.Data.Mkbv_view",
"FStar.Reflection.V1.Data.as_ppname",
"FStar.Reflection.V1.Formula.formula"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_Exists (typ pred: term) : Tac formula | [] | FStar.Reflection.V1.Formula.mk_Exists | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | typ: FStar.Reflection.Types.term -> pred: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.V1.Formula.formula | {
"end_col": 74,
"end_line": 76,
"start_col": 56,
"start_line": 73
} |
FStar.Tactics.Effect.Tac | val term_as_formula_total (t: term) : Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let term_as_formula_total (t:term) : Tac formula =
term_as_formula' (maybe_unsquash_term t) | val term_as_formula_total (t: term) : Tac formula
let term_as_formula_total (t: term) : Tac formula = | true | null | false | term_as_formula' (maybe_unsquash_term t) | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Formula.term_as_formula'",
"FStar.Reflection.V1.Derived.maybe_unsquash_term",
"FStar.Reflection.V1.Formula.formula"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown
// Unsquashing
let term_as_formula (t:term) : Tac formula =
match unsquash_term t with
| None -> F_Unknown
| Some t ->
term_as_formula' t | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val term_as_formula_total (t: term) : Tac formula | [] | FStar.Reflection.V1.Formula.term_as_formula_total | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.V1.Formula.formula | {
"end_col": 44,
"end_line": 164,
"start_col": 4,
"start_line": 164
} |
FStar.Tactics.Effect.Tac | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv})
let rec inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) = | true | null | false | match inspect t with
| Tv_AscribedT t _ _ _ | Tv_AscribedC t _ _ _ -> inspect_unascribe t
| tv -> tv | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Reflection.V1.Formula.inspect_unascribe",
"FStar.Reflection.V1.Data.term_view",
"Prims.b2t",
"FStar.Reflection.V1.Data.notAscription",
"FStar.Reflection.Types.comp",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname) | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | [
"recursion"
] | FStar.Reflection.V1.Formula.inspect_unascribe | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(tv: FStar.Reflection.V1.Data.term_view{FStar.Reflection.V1.Data.notAscription tv}) | {
"end_col": 12,
"end_line": 36,
"start_col": 2,
"start_line": 32
} |
FStar.Tactics.Effect.Tac | val term_as_formula (t: term) : Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let term_as_formula (t:term) : Tac formula =
match unsquash_term t with
| None -> F_Unknown
| Some t ->
term_as_formula' t | val term_as_formula (t: term) : Tac formula
let term_as_formula (t: term) : Tac formula = | true | null | false | match unsquash_term t with
| None -> F_Unknown
| Some t -> term_as_formula' t | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.unsquash_term",
"FStar.Reflection.V1.Formula.F_Unknown",
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Formula.term_as_formula'"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown
// Unsquashing | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val term_as_formula (t: term) : Tac formula | [] | FStar.Reflection.V1.Formula.term_as_formula | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.V1.Formula.formula | {
"end_col": 26,
"end_line": 161,
"start_col": 4,
"start_line": 158
} |
Prims.Tot | val formula_as_term_view (f: formula) : Tot term_view | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let formula_as_term_view (f:formula) : Tot term_view =
let mk_app' tv args = List.Tot.Base.fold_left (fun tv a -> Tv_App (pack_ln tv) a) tv args in
let e = Q_Explicit in
let i = Q_Implicit in
match f with
| True_ -> Tv_FVar (pack_fv true_qn)
| False_ -> Tv_FVar (pack_fv false_qn)
| Comp (Eq None) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(l,e);(r,e)]
| Comp (Eq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(t,i);(l,e);(r,e)]
| Comp (BoolEq None) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(l,e);(r,e)]
| Comp (BoolEq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(t,i);(l,e);(r,e)]
| Comp Lt l r -> mk_app' (Tv_FVar (pack_fv lt_qn)) [(l,e);(r,e)]
| Comp Le l r -> mk_app' (Tv_FVar (pack_fv lte_qn)) [(l,e);(r,e)]
| Comp Gt l r -> mk_app' (Tv_FVar (pack_fv gt_qn)) [(l,e);(r,e)]
| Comp Ge l r -> mk_app' (Tv_FVar (pack_fv gte_qn)) [(l,e);(r,e)]
| And p q -> mk_app' (Tv_FVar (pack_fv and_qn)) [(p,e);(q,e)]
| Or p q -> mk_app' (Tv_FVar (pack_fv or_qn)) [(p,e);(q,e)]
| Implies p q -> mk_app' (Tv_FVar (pack_fv imp_qn)) [(p,e);(q,e)]
| Not p -> mk_app' (Tv_FVar (pack_fv not_qn)) [(p,e)]
| Iff p q -> mk_app' (Tv_FVar (pack_fv iff_qn)) [(p,e);(q,e)]
| Forall b sort t -> Tv_Unknown // TODO: decide on meaning of this
| Exists b sort t -> Tv_Unknown // TODO: ^
| App p q ->
Tv_App p (q, Q_Explicit)
| Name b ->
Tv_Var b
| FV fv ->
Tv_FVar fv
| IntLit i ->
Tv_Const (C_Int i)
| F_Unknown ->
Tv_Unknown | val formula_as_term_view (f: formula) : Tot term_view
let formula_as_term_view (f: formula) : Tot term_view = | false | null | false | let mk_app' tv args = List.Tot.Base.fold_left (fun tv a -> Tv_App (pack_ln tv) a) tv args in
let e = Q_Explicit in
let i = Q_Implicit in
match f with
| True_ -> Tv_FVar (pack_fv true_qn)
| False_ -> Tv_FVar (pack_fv false_qn)
| Comp (Eq None) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(l, e); (r, e)]
| Comp (Eq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(t, i); (l, e); (r, e)]
| Comp (BoolEq None) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(l, e); (r, e)]
| Comp (BoolEq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(t, i); (l, e); (r, e)]
| Comp Lt l r -> mk_app' (Tv_FVar (pack_fv lt_qn)) [(l, e); (r, e)]
| Comp Le l r -> mk_app' (Tv_FVar (pack_fv lte_qn)) [(l, e); (r, e)]
| Comp Gt l r -> mk_app' (Tv_FVar (pack_fv gt_qn)) [(l, e); (r, e)]
| Comp Ge l r -> mk_app' (Tv_FVar (pack_fv gte_qn)) [(l, e); (r, e)]
| And p q -> mk_app' (Tv_FVar (pack_fv and_qn)) [(p, e); (q, e)]
| Or p q -> mk_app' (Tv_FVar (pack_fv or_qn)) [(p, e); (q, e)]
| Implies p q -> mk_app' (Tv_FVar (pack_fv imp_qn)) [(p, e); (q, e)]
| Not p -> mk_app' (Tv_FVar (pack_fv not_qn)) [(p, e)]
| Iff p q -> mk_app' (Tv_FVar (pack_fv iff_qn)) [(p, e); (q, e)]
| Forall b sort t -> Tv_Unknown
| Exists b sort t -> Tv_Unknown
| App p q -> Tv_App p (q, Q_Explicit)
| Name b -> Tv_Var b
| FV fv -> Tv_FVar fv
| IntLit i -> Tv_Const (C_Int i)
| F_Unknown -> Tv_Unknown | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [
"total"
] | [
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Data.Tv_FVar",
"FStar.Reflection.V1.Builtins.pack_fv",
"FStar.Reflection.Const.true_qn",
"FStar.Reflection.Const.false_qn",
"FStar.Reflection.Types.term",
"FStar.Reflection.Const.eq2_qn",
"Prims.Cons",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.aqualv",
"Prims.Nil",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Const.eq1_qn",
"FStar.Reflection.Const.lt_qn",
"FStar.Reflection.Const.lte_qn",
"FStar.Reflection.Const.gt_qn",
"FStar.Reflection.Const.gte_qn",
"FStar.Reflection.Const.and_qn",
"FStar.Reflection.Const.or_qn",
"FStar.Reflection.Const.imp_qn",
"FStar.Reflection.Const.not_qn",
"FStar.Reflection.Const.iff_qn",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Data.Tv_Unknown",
"FStar.Reflection.V1.Data.Tv_App",
"FStar.Reflection.V1.Data.Q_Explicit",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.Reflection.Types.fv",
"Prims.int",
"FStar.Reflection.V1.Data.Tv_Const",
"FStar.Reflection.V1.Data.C_Int",
"FStar.Reflection.V1.Data.term_view",
"FStar.Reflection.V1.Data.Q_Implicit",
"Prims.list",
"FStar.List.Tot.Base.fold_left",
"FStar.Reflection.V1.Builtins.pack_ln"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown
// Unsquashing
let term_as_formula (t:term) : Tac formula =
match unsquash_term t with
| None -> F_Unknown
| Some t ->
term_as_formula' t
let term_as_formula_total (t:term) : Tac formula =
term_as_formula' (maybe_unsquash_term t) | false | true | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val formula_as_term_view (f: formula) : Tot term_view | [] | FStar.Reflection.V1.Formula.formula_as_term_view | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: FStar.Reflection.V1.Formula.formula -> FStar.Reflection.V1.Data.term_view | {
"end_col": 18,
"end_line": 202,
"start_col": 54,
"start_line": 166
} |
FStar.Tactics.Effect.Tac | val formula_to_string (f: formula) : Tac string | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let formula_to_string (f:formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp (Eq mt) l r -> "Eq" ^
(match mt with
| None -> ""
| Some t -> " (" ^ term_to_string t ^ ")") ^
" (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp (BoolEq mt) l r -> "BoolEq" ^
(match mt with
| None -> ""
| Some t -> " (" ^ term_to_string t ^ ")") ^
" (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Lt l r -> "Lt (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Le l r -> "Le (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Gt l r -> "Gt (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Ge l r -> "Ge (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| And p q -> "And (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Or p q -> "Or (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Implies p q -> "Implies (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Not p -> "Not (" ^ term_to_string p ^ ")"
| Iff p q -> "Iff (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Forall bs _sort t -> "Forall <bs> (" ^ term_to_string t ^ ")"
| Exists bs _sort t -> "Exists <bs> (" ^ term_to_string t ^ ")"
| App p q -> "App (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Name bv -> "Name (" ^ bv_to_string bv ^ ")"
| FV fv -> "FV (" ^ flatten_name (inspect_fv fv) ^ ")"
| IntLit i -> "Int " ^ string_of_int i
| F_Unknown -> "?" | val formula_to_string (f: formula) : Tac string
let formula_to_string (f: formula) : Tac string = | true | null | false | match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp (Eq mt) l r ->
"Eq" ^
(match mt with
| None -> ""
| Some t -> " (" ^ term_to_string t ^ ")") ^
" (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp (BoolEq mt) l r ->
"BoolEq" ^
(match mt with
| None -> ""
| Some t -> " (" ^ term_to_string t ^ ")") ^
" (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Lt l r -> "Lt (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Le l r -> "Le (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Gt l r -> "Gt (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| Comp Ge l r -> "Ge (" ^ term_to_string l ^ ") (" ^ term_to_string r ^ ")"
| And p q -> "And (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Or p q -> "Or (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Implies p q -> "Implies (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Not p -> "Not (" ^ term_to_string p ^ ")"
| Iff p q -> "Iff (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Forall bs _sort t -> "Forall <bs> (" ^ term_to_string t ^ ")"
| Exists bs _sort t -> "Exists <bs> (" ^ term_to_string t ^ ")"
| App p q -> "App (" ^ term_to_string p ^ ") (" ^ term_to_string q ^ ")"
| Name bv -> "Name (" ^ bv_to_string bv ^ ")"
| FV fv -> "FV (" ^ flatten_name (inspect_fv fv) ^ ")"
| IntLit i -> "Int " ^ string_of_int i
| F_Unknown -> "?" | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.V1.Formula.formula",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Types.term",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Formula.bv_to_string",
"FStar.Reflection.Types.fv",
"FStar.Reflection.V1.Derived.flatten_name",
"FStar.Reflection.V1.Builtins.inspect_fv",
"Prims.int",
"Prims.string_of_int"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown
// Unsquashing
let term_as_formula (t:term) : Tac formula =
match unsquash_term t with
| None -> F_Unknown
| Some t ->
term_as_formula' t
let term_as_formula_total (t:term) : Tac formula =
term_as_formula' (maybe_unsquash_term t)
let formula_as_term_view (f:formula) : Tot term_view =
let mk_app' tv args = List.Tot.Base.fold_left (fun tv a -> Tv_App (pack_ln tv) a) tv args in
let e = Q_Explicit in
let i = Q_Implicit in
match f with
| True_ -> Tv_FVar (pack_fv true_qn)
| False_ -> Tv_FVar (pack_fv false_qn)
| Comp (Eq None) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(l,e);(r,e)]
| Comp (Eq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq2_qn)) [(t,i);(l,e);(r,e)]
| Comp (BoolEq None) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(l,e);(r,e)]
| Comp (BoolEq (Some t)) l r -> mk_app' (Tv_FVar (pack_fv eq1_qn)) [(t,i);(l,e);(r,e)]
| Comp Lt l r -> mk_app' (Tv_FVar (pack_fv lt_qn)) [(l,e);(r,e)]
| Comp Le l r -> mk_app' (Tv_FVar (pack_fv lte_qn)) [(l,e);(r,e)]
| Comp Gt l r -> mk_app' (Tv_FVar (pack_fv gt_qn)) [(l,e);(r,e)]
| Comp Ge l r -> mk_app' (Tv_FVar (pack_fv gte_qn)) [(l,e);(r,e)]
| And p q -> mk_app' (Tv_FVar (pack_fv and_qn)) [(p,e);(q,e)]
| Or p q -> mk_app' (Tv_FVar (pack_fv or_qn)) [(p,e);(q,e)]
| Implies p q -> mk_app' (Tv_FVar (pack_fv imp_qn)) [(p,e);(q,e)]
| Not p -> mk_app' (Tv_FVar (pack_fv not_qn)) [(p,e)]
| Iff p q -> mk_app' (Tv_FVar (pack_fv iff_qn)) [(p,e);(q,e)]
| Forall b sort t -> Tv_Unknown // TODO: decide on meaning of this
| Exists b sort t -> Tv_Unknown // TODO: ^
| App p q ->
Tv_App p (q, Q_Explicit)
| Name b ->
Tv_Var b
| FV fv ->
Tv_FVar fv
| IntLit i ->
Tv_Const (C_Int i)
| F_Unknown ->
Tv_Unknown
let formula_as_term (f:formula) : Tot term =
pack_ln (formula_as_term_view f) | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val formula_to_string (f: formula) : Tac string | [] | FStar.Reflection.V1.Formula.formula_to_string | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: FStar.Reflection.V1.Formula.formula -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 22,
"end_line": 236,
"start_col": 4,
"start_line": 208
} |
FStar.Tactics.Effect.Tac | val term_as_formula' (t: term) : Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let term_as_formula' (t:term) : Tac formula =
match inspect_unascribe t with
| Tv_Var n ->
Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
// Cannot use `when` clauses when verifying!
let qn = inspect_fv fv in
if qn = true_qn then True_
else if qn = false_qn then False_
else FV fv
// TODO: l_Forall
// ...or should we just try to drop all squashes?
// TODO: b2t at this point ?
| Tv_App h0 t -> begin
let (h, ts) = collect_app h0 in
let h = un_uinst h in
match inspect_ln h, ts@[t] with
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit); (a3, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = eq2_qn then Comp (Eq (Some a1)) a2 a3
else if qn = eq1_qn then Comp (BoolEq (Some a1)) a2 a3
else if qn = lt_qn then Comp Lt a2 a3
else if qn = lte_qn then Comp Le a2 a3
else if qn = gt_qn then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = imp_qn then Implies a1 a2
else if qn = and_qn then And a1 a2
else if qn = iff_qn then Iff a1 a2
else if qn = or_qn then Or a1 a2
// Non-annotated comparisons
else if qn = eq2_qn then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a1, Q_Implicit); (a2, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = forall_qn then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2
else App h0 (fst t)
| Tv_FVar fv, [(a, Q_Explicit)] ->
let qn = inspect_fv fv in
if qn = not_qn then Not a
else if qn = b2t_qn then begin
if term_eq a (`false) then False_
else if term_eq a (`true) then True_
else App h0 (fst t)
end
else App h0 (fst t)
| _ ->
App h0 (fst t)
end
| Tv_Const (C_Int i) ->
IntLit i
(* Not formulas. *)
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
(* Other constants? *)
| Tv_Const _ -> F_Unknown
(* Should not occur, we're using inspect_ln *)
| Tv_BVar _ -> F_Unknown | val term_as_formula' (t: term) : Tac formula
let term_as_formula' (t: term) : Tac formula = | true | null | false | match inspect_unascribe t with
| Tv_Var n -> Name n
| Tv_FVar fv
| Tv_UInst fv _ ->
let qn = inspect_fv fv in
if qn = true_qn then True_ else if qn = false_qn then False_ else FV fv
| Tv_App h0 t ->
let h, ts = collect_app h0 in
let h = un_uinst h in
(match inspect_ln h, ts @ [t] with
| Tv_FVar fv, [a1, Q_Implicit ; a2, Q_Explicit ; a3, Q_Explicit] ->
let qn = inspect_fv fv in
if qn = eq2_qn
then Comp (Eq (Some a1)) a2 a3
else
if qn = eq1_qn
then Comp (BoolEq (Some a1)) a2 a3
else
if qn = lt_qn
then Comp Lt a2 a3
else
if qn = lte_qn
then Comp Le a2 a3
else
if qn = gt_qn
then Comp Gt a2 a3
else if qn = gte_qn then Comp Ge a2 a3 else App h0 (fst t)
| Tv_FVar fv, [a1, Q_Explicit ; a2, Q_Explicit] ->
let qn = inspect_fv fv in
if qn = imp_qn
then Implies a1 a2
else
if qn = and_qn
then And a1 a2
else
if qn = iff_qn
then Iff a1 a2
else
if qn = or_qn
then Or a1 a2
else
if qn = eq2_qn
then Comp (Eq None) a1 a2
else if qn = eq1_qn then Comp (BoolEq None) a1 a2 else App h0 (fst t)
| Tv_FVar fv, [a1, Q_Implicit ; a2, Q_Explicit] ->
let qn = inspect_fv fv in
if qn = forall_qn
then mk_Forall a1 a2
else if qn = exists_qn then mk_Exists a1 a2 else App h0 (fst t)
| Tv_FVar fv, [a, Q_Explicit] ->
let qn = inspect_fv fv in
if qn = not_qn
then Not a
else
if qn = b2t_qn
then
if term_eq a (`false) then False_ else if term_eq a (`true) then True_ else App h0 (fst t)
else App h0 (fst t)
| _ -> App h0 (fst t))
| Tv_Const (C_Int i) -> IntLit i
| Tv_Let _ _ _ _ _ _
| Tv_Match _ _ _
| Tv_Type _
| Tv_Abs _ _
| Tv_Arrow _ _
| Tv_Uvar _ _
| Tv_Unknown
| Tv_Unsupp
| Tv_Refine _ _ _ -> F_Unknown
| Tv_Const _ -> F_Unknown
| Tv_BVar _ -> F_Unknown | {
"checked_file": "FStar.Reflection.V1.Formula.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Formula.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Formula.Name",
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"FStar.Reflection.Const.true_qn",
"FStar.Reflection.V1.Formula.True_",
"Prims.bool",
"FStar.Reflection.Const.false_qn",
"FStar.Reflection.V1.Formula.False_",
"FStar.Reflection.V1.Formula.FV",
"FStar.Reflection.Types.name",
"FStar.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.V1.Data.universes",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Builtins.inspect_ln",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.Const.eq2_qn",
"FStar.Reflection.V1.Formula.Comp",
"FStar.Reflection.V1.Formula.Eq",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Const.eq1_qn",
"FStar.Reflection.V1.Formula.BoolEq",
"FStar.Reflection.Const.lt_qn",
"FStar.Reflection.V1.Formula.Lt",
"FStar.Reflection.Const.lte_qn",
"FStar.Reflection.V1.Formula.Le",
"FStar.Reflection.Const.gt_qn",
"FStar.Reflection.V1.Formula.Gt",
"FStar.Reflection.Const.gte_qn",
"FStar.Reflection.V1.Formula.Ge",
"FStar.Reflection.V1.Formula.App",
"FStar.Pervasives.Native.fst",
"FStar.Reflection.Const.imp_qn",
"FStar.Reflection.V1.Formula.Implies",
"FStar.Reflection.Const.and_qn",
"FStar.Reflection.V1.Formula.And",
"FStar.Reflection.Const.iff_qn",
"FStar.Reflection.V1.Formula.Iff",
"FStar.Reflection.Const.or_qn",
"FStar.Reflection.V1.Formula.Or",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Const.forall_qn",
"FStar.Reflection.V1.Formula.mk_Forall",
"FStar.Reflection.Const.exists_qn",
"FStar.Reflection.V1.Formula.mk_Exists",
"FStar.Reflection.Const.not_qn",
"FStar.Reflection.V1.Formula.Not",
"FStar.Reflection.Const.b2t_qn",
"FStar.Reflection.V1.Builtins.term_eq",
"FStar.Reflection.V1.Derived.un_uinst",
"FStar.Reflection.V1.Formula.collect_app",
"Prims.int",
"FStar.Reflection.V1.Formula.IntLit",
"FStar.Reflection.V1.Formula.F_Unknown",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.match_returns_ascription",
"FStar.Reflection.V1.Data.branch",
"FStar.Reflection.Types.universe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"Prims.nat",
"FStar.Reflection.Types.ctx_uvar_and_subst",
"FStar.Reflection.V1.Data.vconst",
"Prims.b2t",
"FStar.Reflection.V1.Data.notAscription",
"FStar.Reflection.V1.Formula.inspect_unascribe"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Formula
open FStar.List.Tot.Base
open FStar.Tactics.Effect
open FStar.Tactics.V1.Builtins
open FStar.Reflection.Types
open FStar.Reflection.Const
open FStar.Reflection.V1.Builtins
open FStar.Reflection.V1.Derived
open FStar.Reflection.V1.Data
///// Cannot open FStar.Tactics.Derived here /////
private let bv_to_string (bv : bv) : Tac string =
let bvv = inspect_bv bv in
unseal (bvv.bv_ppname)
private let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
private let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args)
private let collect_app = collect_app' []
/////
noeq type comparison =
| Eq of option typ (* Propositional equality (eq2), maybe annotated *)
| BoolEq of option typ (* Decidable, boolean equality (eq), maybe annotated *)
| Lt | Le | Gt | Ge (* Orderings, at type `int` (and subtypes) *)
noeq type formula =
| True_ : formula
| False_ : formula
| Comp : comparison -> term -> term -> formula
| And : term -> term -> formula
| Or : term -> term -> formula
| Not : term -> formula
| Implies: term -> term -> formula
| Iff : term -> term -> formula
| Forall : bv -> typ -> term -> formula
| Exists : bv -> typ -> term -> formula
| App : term -> term -> formula
| Name : bv -> formula
| FV : fv -> formula
| IntLit : int -> formula
| F_Unknown : formula // Also a baked-in "None"
let mk_Forall (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Forall b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit)))
let mk_Exists (typ : term) (pred : term) : Tac formula =
let b = pack_bv ({ bv_ppname = as_ppname "x";
bv_index = 0; }) in
Exists b typ (pack_ln (Tv_App pred (pack_ln (Tv_BVar b), Q_Explicit))) | false | false | FStar.Reflection.V1.Formula.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val term_as_formula' (t: term) : Tac formula | [] | FStar.Reflection.V1.Formula.term_as_formula' | {
"file_name": "ulib/FStar.Reflection.V1.Formula.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.V1.Formula.formula | {
"end_col": 28,
"end_line": 154,
"start_col": 4,
"start_line": 79
} |
Prims.Tot | val pts_to_sl (#a:Type0) (r:ref a) (p:perm) (v:a) : slprop u#1 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v) | val pts_to_sl (#a:Type0) (r:ref a) (p:perm) (v:a) : slprop u#1
let pts_to_sl r p v = | false | null | false | H.pts_to_sl r p (U.raise_val v) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.HigherReference.pts_to_sl",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Steel.Memory.slprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to_sl (#a:Type0) (r:ref a) (p:perm) (v:a) : slprop u#1 | [] | Steel.Reference.pts_to_sl | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> v: a -> Steel.Memory.slprop | {
"end_col": 53,
"end_line": 34,
"start_col": 22,
"start_line": 34
} |
Prims.Tot | val ptrp (#a:Type0) (r:ref a) ([@@@smt_fallback] p: perm) : slprop u#1 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptrp r p = Mem.h_exists (pts_to_sl r p) | val ptrp (#a:Type0) (r:ref a) ([@@@smt_fallback] p: perm) : slprop u#1
let ptrp r p = | false | null | false | Mem.h_exists (pts_to_sl r p) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.h_exists",
"Steel.Reference.pts_to_sl",
"Steel.Memory.slprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptrp (#a:Type0) (r:ref a) ([@@@smt_fallback] p: perm) : slprop u#1 | [] | Steel.Reference.ptrp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> Steel.Memory.slprop | {
"end_col": 43,
"end_line": 242,
"start_col": 15,
"start_line": 242
} |
Prims.Tot | val ref ([@@@unused] a:Type0) : Type0 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ref a = H.ref (U.raise_t a) | val ref ([@@@unused] a:Type0) : Type0
let ref a = | false | null | false | H.ref (U.raise_t a) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.HigherReference.ref",
"FStar.Universe.raise_t"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off" | false | true | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ref ([@@@unused] a:Type0) : Type0 | [] | Steel.Reference.ref | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Type0 -> Type0 | {
"end_col": 31,
"end_line": 29,
"start_col": 12,
"start_line": 29
} |
Prims.Tot | val ghost_ptrp (#a: Type0) (r: ghost_ref a) ([@@@smt_fallback] p: perm) : slprop u#1 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p) | val ghost_ptrp (#a: Type0) (r: ghost_ref a) ([@@@smt_fallback] p: perm) : slprop u#1
let ghost_ptrp r p = | false | null | false | Mem.h_exists (ghost_pts_to_sl r p) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.h_exists",
"Steel.Reference.ghost_pts_to_sl",
"Steel.Memory.slprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptrp (#a: Type0) (r: ghost_ref a) ([@@@smt_fallback] p: perm) : slprop u#1 | [] | Steel.Reference.ghost_ptrp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm -> Steel.Memory.slprop | {
"end_col": 55,
"end_line": 429,
"start_col": 21,
"start_line": 429
} |
Prims.Tot | val null (#a:Type0) : ref a | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let null #a = H.null #(U.raise_t a) | val null (#a:Type0) : ref a
let null #a = | false | null | false | H.null #(U.raise_t a) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.HigherReference.null",
"FStar.Universe.raise_t",
"Steel.Reference.ref"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val null (#a:Type0) : ref a | [] | Steel.Reference.null | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Steel.Reference.ref a | {
"end_col": 35,
"end_line": 31,
"start_col": 14,
"start_line": 31
} |
Steel.Effect.Atomic.SteelGhost | val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p v)
(fun _ -> ghost_pts_to r p v)
(fun _ -> True)
(fun _ _ _ -> p `lesser_equal_perm` full_perm) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_pts_to_perm r = H.ghost_pts_to_perm r | val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p v)
(fun _ -> ghost_pts_to r p v)
(fun _ -> True)
(fun _ _ _ -> p `lesser_equal_perm` full_perm)
let ghost_pts_to_perm r = | true | null | false | H.ghost_pts_to_perm r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.Reference.ghost_ref",
"Steel.HigherReference.ghost_pts_to_perm",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p v)
(fun _ -> ghost_pts_to r p v)
(fun _ -> True)
(fun _ _ _ -> p `lesser_equal_perm` full_perm) | [] | Steel.Reference.ghost_pts_to_perm | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 47,
"end_line": 413,
"start_col": 26,
"start_line": 413
} |
FStar.Pervasives.Lemma | val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) | val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p))
let pts_to_witinv (#a: Type) (r: ref a) (p: perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = | false | null | true | let aux (x y: a) (m: mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y))
=
H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Classical.forall_intro_3",
"Steel.Memory.mem",
"Prims.l_imp",
"Prims.l_and",
"Steel.Memory.interp",
"Steel.Reference.pts_to_sl",
"Prims.eq2",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Steel.Reference.raise_val_inj",
"Steel.HigherReference.pts_to_witinv",
"FStar.Universe.raise_t",
"Steel.Memory.is_witness_invariant"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = () | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) | [] | Steel.Reference.pts_to_witinv | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm
-> FStar.Pervasives.Lemma
(ensures Steel.Memory.is_witness_invariant (Steel.Reference.pts_to_sl r p)) | {
"end_col": 73,
"end_line": 88,
"start_col": 95,
"start_line": 81
} |
Prims.Tot | val ptrp_sel (#a:Type0) (r:ref a) (p: perm) : selector a (ptrp r p) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p | val ptrp_sel (#a:Type0) (r:ref a) (p: perm) : selector a (ptrp r p)
let ptrp_sel r p = | false | null | false | Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Reference.ptr_sel'",
"Prims.unit",
"FStar.Classical.forall_intro",
"Steel.Memory.hmem",
"Steel.Reference.ptrp",
"Prims.eq2",
"Steel.Memory.core_mem",
"Steel.Reference.ptr_sel_depends_only_on_core",
"FStar.Classical.forall_intro_2",
"Steel.Memory.mem",
"Steel.Memory.disjoint",
"Steel.Memory.join",
"Steel.Reference.ptr_sel_depends_only_on",
"Steel.Effect.Common.selector"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptrp_sel (#a:Type0) (r:ref a) (p: perm) : selector a (ptrp r p) | [] | Steel.Reference.ptrp_sel | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Common.selector a (Steel.Reference.ptrp r p) | {
"end_col": 14,
"end_line": 267,
"start_col": 2,
"start_line": 265
} |
FStar.Pervasives.Lemma | val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y | val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y = | false | null | true | U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"FStar.Universe.downgrade_val_raise_val",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y) | [] | Steel.Reference.raise_val_inj | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> y: a
-> FStar.Pervasives.Lemma (requires FStar.Universe.raise_val x == FStar.Universe.raise_val y)
(ensures x == y) | {
"end_col": 29,
"end_line": 42,
"start_col": 2,
"start_line": 41
} |
Prims.Tot | val is_null (#a:Type0) (r:ref a) : (b:bool{b <==> r == null}) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_null #a r = H.is_null #(U.raise_t a) r | val is_null (#a:Type0) (r:ref a) : (b:bool{b <==> r == null})
let is_null #a r = | false | null | false | H.is_null #(U.raise_t a) r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ref",
"Steel.HigherReference.is_null",
"FStar.Universe.raise_t",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2",
"Steel.Reference.null"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_null (#a:Type0) (r:ref a) : (b:bool{b <==> r == null}) | [] | Steel.Reference.is_null | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> b: Prims.bool{b <==> r == Steel.Reference.null} | {
"end_col": 45,
"end_line": 32,
"start_col": 19,
"start_line": 32
} |
FStar.Pervasives.Lemma | val raise_equiv (#t: Type) (x y: t) : Lemma (U.raise_val x == U.raise_val y <==> x == y) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y) | val raise_equiv (#t: Type) (x y: t) : Lemma (U.raise_val x == U.raise_val y <==> x == y)
let raise_equiv (#t: Type) (x y: t) : Lemma (U.raise_val x == U.raise_val y <==> x == y) = | false | null | true | assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Prims._assert",
"Prims.eq2",
"FStar.Universe.downgrade_val",
"FStar.Universe.raise_val",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"FStar.Universe.raise_t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==> | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val raise_equiv (#t: Type) (x y: t) : Lemma (U.raise_val x == U.raise_val y <==> x == y) | [] | Steel.Reference.raise_equiv | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: t -> y: t
-> FStar.Pervasives.Lemma
(ensures FStar.Universe.raise_val x == FStar.Universe.raise_val y <==> x == y) | {
"end_col": 49,
"end_line": 162,
"start_col": 4,
"start_line": 161
} |
FStar.Pervasives.Lemma | val intro_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p | val intro_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
let intro_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v) = | false | null | true | Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Memory.mem",
"Steel.Reference.pts_to_witinv",
"Prims.unit",
"Steel.Memory.intro_h_exists",
"FStar.Ghost.reveal",
"Steel.Reference.pts_to_sl",
"Steel.Memory.interp",
"Prims.squash",
"Prims.l_and",
"Steel.Reference.ptrp",
"Prims.eq2",
"Steel.Reference.ptrp_sel",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v) | [] | Steel.Reference.intro_vptr_lemma | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p: Steel.FractionalPermission.perm ->
v: FStar.Ghost.erased a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires Steel.Memory.interp (Steel.Reference.pts_to_sl r p (FStar.Ghost.reveal v)) m)
(ensures
Steel.Memory.interp (Steel.Reference.ptrp r p) m /\
Steel.Reference.ptrp_sel r p m == FStar.Ghost.reveal v) | {
"end_col": 21,
"end_line": 277,
"start_col": 4,
"start_line": 276
} |
FStar.Pervasives.Lemma | val elim_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p | val elim_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
let elim_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m) = | false | null | true | Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Memory.mem",
"Steel.Reference.pts_to_witinv",
"Prims.unit",
"Steel.Memory.elim_h_exists",
"Steel.Reference.pts_to_sl",
"Prims.l_and",
"Steel.Memory.interp",
"Steel.Reference.ptrp",
"Prims.eq2",
"Steel.Reference.ptrp_sel",
"FStar.Ghost.reveal",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_vptr_lemma (#a: Type) (r: ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m) | [] | Steel.Reference.elim_vptr_lemma | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p: Steel.FractionalPermission.perm ->
v: FStar.Ghost.erased a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires
Steel.Memory.interp (Steel.Reference.ptrp r p) m /\
Steel.Reference.ptrp_sel r p m == FStar.Ghost.reveal v)
(ensures Steel.Memory.interp (Steel.Reference.pts_to_sl r p (FStar.Ghost.reveal v)) m) | {
"end_col": 21,
"end_line": 283,
"start_col": 4,
"start_line": 282
} |
FStar.Pervasives.Lemma | val ptrp_sel_interp (#a:Type0) (r:ref a) (p: perm) (m:mem) : Lemma
(requires interp (ptrp r p) m)
(ensures interp (pts_to_sl r p (ptrp_sel r p m)) m) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptrp_sel_interp #a r p m = pts_to_witinv r p | val ptrp_sel_interp (#a:Type0) (r:ref a) (p: perm) (m:mem) : Lemma
(requires interp (ptrp r p) m)
(ensures interp (pts_to_sl r p (ptrp_sel r p m)) m)
let ptrp_sel_interp #a r p m = | false | null | true | pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.mem",
"Steel.Reference.pts_to_witinv",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptrp_sel_interp (#a:Type0) (r:ref a) (p: perm) (m:mem) : Lemma
(requires interp (ptrp r p) m)
(ensures interp (pts_to_sl r p (ptrp_sel r p m)) m) | [] | Steel.Reference.ptrp_sel_interp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> m: Steel.Memory.mem
-> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Reference.ptrp r p) m)
(ensures
Steel.Memory.interp (Steel.Reference.pts_to_sl r p (Steel.Reference.ptrp_sel r p m)) m) | {
"end_col": 48,
"end_line": 269,
"start_col": 31,
"start_line": 269
} |
FStar.Pervasives.Lemma | val elim_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p | val elim_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
let elim_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m) = | false | null | true | Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Memory.mem",
"Steel.Reference.ghost_pts_to_witinv",
"Prims.unit",
"Steel.Memory.elim_h_exists",
"Steel.Reference.ghost_pts_to_sl",
"Prims.l_and",
"Steel.Memory.interp",
"Steel.Reference.ghost_ptrp",
"Prims.eq2",
"Steel.Reference.ghost_ptrp_sel",
"FStar.Ghost.reveal",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m) | [] | Steel.Reference.elim_ghost_vptr_lemma | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ghost_ref a ->
p: Steel.FractionalPermission.perm ->
v: FStar.Ghost.erased a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires
Steel.Memory.interp (Steel.Reference.ghost_ptrp r p) m /\
Steel.Reference.ghost_ptrp_sel r p m == FStar.Ghost.reveal v)
(ensures Steel.Memory.interp (Steel.Reference.ghost_pts_to_sl r p (FStar.Ghost.reveal v)) m) | {
"end_col": 27,
"end_line": 469,
"start_col": 4,
"start_line": 468
} |
FStar.Pervasives.Lemma | val pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m | val pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
let pts_to_not_null (#a: Type u#0) (x: ref a) (p: perm) (v: a) (m: mem)
: Lemma (requires interp (pts_to_sl x p v) m) (ensures x =!= null) = | false | null | true | let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.mem",
"Steel.HigherReference.pts_to_not_null",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Prims.unit",
"Steel.Memory.interp",
"Steel.Reference.pts_to_sl",
"Prims.squash",
"Prims.l_not",
"Prims.eq2",
"Steel.Reference.null",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null) | [] | Steel.Reference.pts_to_not_null | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> v: a -> m: Steel.Memory.mem
-> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Reference.pts_to_sl x p v) m)
(ensures ~(x == Steel.Reference.null)) | {
"end_col": 44,
"end_line": 68,
"start_col": 3,
"start_line": 67
} |
Prims.Tot | val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h | val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = | false | null | false | fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ghost_ptrp",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Steel.Reference.ghost_pts_to_sl"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p) | [] | Steel.Reference.ghost_ptr_sel' | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Common.selector' a (Steel.Reference.ghost_ptrp r p) | {
"end_col": 78,
"end_line": 432,
"start_col": 28,
"start_line": 432
} |
FStar.Pervasives.Lemma | val ghost_ptr_sel_depends_only_on
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1) | val ghost_ptr_sel_depends_only_on
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
let ghost_ptr_sel_depends_only_on
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1)) = | false | null | true | let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ghost_ptrp",
"Steel.Memory.mem",
"Steel.Memory.disjoint",
"Steel.Memory.elim_wi",
"Steel.Reference.ghost_pts_to_sl",
"Steel.Memory.join",
"Prims.unit",
"Steel.Reference.ghost_pts_to_witinv",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Steel.Reference.ghost_ptr_sel'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1}) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptr_sel_depends_only_on
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1)) | [] | Steel.Reference.ghost_ptr_sel_depends_only_on | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ghost_ref a ->
p: Steel.FractionalPermission.perm ->
m0: Steel.Memory.hmem (Steel.Reference.ghost_ptrp r p) ->
m1: Steel.Memory.mem{Steel.Memory.disjoint m0 m1}
-> FStar.Pervasives.Lemma
(ensures
Steel.Reference.ghost_ptr_sel' r p m0 ==
Steel.Reference.ghost_ptr_sel' r p (Steel.Memory.join m0 m1)) | {
"end_col": 54,
"end_line": 441,
"start_col": 3,
"start_line": 438
} |
FStar.Pervasives.Lemma | val intro_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p | val intro_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
let intro_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v) = | false | null | true | Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Memory.mem",
"Steel.Reference.ghost_pts_to_witinv",
"Prims.unit",
"Steel.Memory.intro_h_exists",
"FStar.Ghost.reveal",
"Steel.Reference.ghost_pts_to_sl",
"Steel.Memory.interp",
"Prims.squash",
"Prims.l_and",
"Steel.Reference.ghost_ptrp",
"Prims.eq2",
"Steel.Reference.ghost_ptrp_sel",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_ghost_vptr_lemma (#a: Type) (r: ghost_ref a) (p: perm) (v: erased a) (m: mem)
: Lemma (requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v) | [] | Steel.Reference.intro_ghost_vptr_lemma | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ghost_ref a ->
p: Steel.FractionalPermission.perm ->
v: FStar.Ghost.erased a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires Steel.Memory.interp (Steel.Reference.ghost_pts_to_sl r p (FStar.Ghost.reveal v)) m)
(ensures
Steel.Memory.interp (Steel.Reference.ghost_ptrp r p) m /\
Steel.Reference.ghost_ptrp_sel r p m == FStar.Ghost.reveal v) | {
"end_col": 27,
"end_line": 463,
"start_col": 4,
"start_line": 462
} |
Steel.Effect.Atomic.SteelGhostT | val ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
: SteelGhostT unit u
(ghost_pts_to r p x)
(fun _ -> ghost_pts_to r (half_perm p) x `star`
ghost_pts_to r (half_perm p) x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r | val ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
: SteelGhostT unit u
(ghost_pts_to r p x)
(fun _ -> ghost_pts_to r (half_perm p) x `star`
ghost_pts_to r (half_perm p) x)
let ghost_share_pt (#a: Type) (#u: _) (#p: perm) (#x: erased a) (r: ghost_ref a) = | true | null | false | H.ghost_share #_ #_ #_ #(raise_erased x) r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Steel.HigherReference.ghost_share",
"FStar.Universe.raise_t",
"Steel.Reference.raise_erased",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
: SteelGhostT unit u
(ghost_pts_to r p x)
(fun _ -> ghost_pts_to r (half_perm p) x `star`
ghost_pts_to r (half_perm p) x) | [] | Steel.Reference.ghost_share_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhostT Prims.unit | {
"end_col": 47,
"end_line": 391,
"start_col": 5,
"start_line": 391
} |
FStar.Pervasives.Lemma | val ptr_sel_depends_only_on
(#a: Type0)
(r: ref a)
(p: perm)
(m0: Mem.hmem (ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1) | val ptr_sel_depends_only_on
(#a: Type0)
(r: ref a)
(p: perm)
(m0: Mem.hmem (ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
let ptr_sel_depends_only_on
(#a: Type0)
(r: ref a)
(p: perm)
(m0: Mem.hmem (ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1)) = | false | null | true | let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ptrp",
"Steel.Memory.mem",
"Steel.Memory.disjoint",
"Steel.Memory.elim_wi",
"Steel.Reference.pts_to_sl",
"Steel.Memory.join",
"Prims.unit",
"Steel.Reference.pts_to_witinv",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Steel.Reference.ptr_sel'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1}) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptr_sel_depends_only_on
(#a: Type0)
(r: ref a)
(p: perm)
(m0: Mem.hmem (ptrp r p))
(m1: mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1)) | [] | Steel.Reference.ptr_sel_depends_only_on | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p: Steel.FractionalPermission.perm ->
m0: Steel.Memory.hmem (Steel.Reference.ptrp r p) ->
m1: Steel.Memory.mem{Steel.Memory.disjoint m0 m1}
-> FStar.Pervasives.Lemma
(ensures
Steel.Reference.ptr_sel' r p m0 == Steel.Reference.ptr_sel' r p (Steel.Memory.join m0 m1)) | {
"end_col": 48,
"end_line": 254,
"start_col": 3,
"start_line": 251
} |
Steel.Memory.MstTot | val cas_action
(#t: eqtype)
(#uses: inames)
(r: ref t)
(v: Ghost.erased t)
(v_old v_new: t)
(frame: slprop)
: MstTot (b: bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b | val cas_action
(#t: eqtype)
(#uses: inames)
(r: ref t)
(v: Ghost.erased t)
(v_old v_new: t)
(frame: slprop)
: MstTot (b: bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
let cas_action
(#t: eqtype)
(#uses: inames)
(r: ref t)
(v: Ghost.erased t)
(v_old v_new: t)
(frame: slprop)
: MstTot (b: bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True) = | true | null | false | let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b =
H.cas_action #(U.raise_t t) (lift_eq #t) #uses r hv (U.raise_val v_old) (U.raise_val v_new) frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Prims.eqtype",
"Steel.Memory.inames",
"Steel.Reference.ref",
"FStar.Ghost.erased",
"Steel.Memory.slprop",
"Prims.unit",
"Steel.Reference.raise_equiv",
"FStar.Ghost.reveal",
"Prims._assert",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Prims.bool",
"Steel.HigherReference.cas_action",
"Steel.Reference.lift_eq",
"FStar.Ghost.hide",
"Steel.Reference.pts_to_sl",
"Steel.FractionalPermission.full_perm",
"Steel.Memory.mem",
"Prims.l_True",
"Prims.prop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cas_action
(#t: eqtype)
(#uses: inames)
(r: ref t)
(v: Ghost.erased t)
(v_old v_new: t)
(frame: slprop)
: MstTot (b: bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True) | [] | Steel.Reference.cas_action | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref t ->
v: FStar.Ghost.erased t ->
v_old: t ->
v_new: t ->
frame: Steel.Memory.slprop
-> Steel.Memory.MstTot (b: Prims.bool{b <==> FStar.Ghost.reveal v == v_old}) | {
"end_col": 6,
"end_line": 203,
"start_col": 4,
"start_line": 190
} |
FStar.Pervasives.Lemma | val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm)
: Lemma (is_witness_invariant (ghost_pts_to_sl r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) | val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm)
: Lemma (is_witness_invariant (ghost_pts_to_sl r p))
let ghost_pts_to_witinv (#a: Type) (r: ghost_ref a) (p: perm)
: Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = | false | null | true | let aux (x y: a) (m: mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y)) =
H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Classical.forall_intro_3",
"Steel.Memory.mem",
"Prims.l_imp",
"Prims.l_and",
"Steel.Memory.interp",
"Steel.Reference.ghost_pts_to_sl",
"Prims.eq2",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Steel.Reference.raise_val_inj",
"Steel.HigherReference.ghost_pts_to_witinv",
"FStar.Universe.raise_t",
"Steel.Memory.is_witness_invariant"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm)
: Lemma (is_witness_invariant (ghost_pts_to_sl r p)) | [] | Steel.Reference.ghost_pts_to_witinv | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm
-> FStar.Pervasives.Lemma
(ensures Steel.Memory.is_witness_invariant (Steel.Reference.ghost_pts_to_sl r p)) | {
"end_col": 73,
"end_line": 372,
"start_col": 113,
"start_line": 365
} |
FStar.Pervasives.Lemma | val ghost_ptr_sel_depends_only_on_core
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0) | val ghost_ptr_sel_depends_only_on_core
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
let ghost_ptr_sel_depends_only_on_core
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0)) = | false | null | true | let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ghost_ptrp",
"Steel.Memory.elim_wi",
"Steel.Reference.ghost_pts_to_sl",
"Steel.Memory.core_mem",
"Prims.unit",
"Steel.Reference.ghost_pts_to_witinv",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Steel.Reference.ghost_ptr_sel'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p)) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptr_sel_depends_only_on_core
(#a: Type0)
(r: ghost_ref a)
(p: perm)
(m0: Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0)) | [] | Steel.Reference.ghost_ptr_sel_depends_only_on_core | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ghost_ref a ->
p: Steel.FractionalPermission.perm ->
m0: Steel.Memory.hmem (Steel.Reference.ghost_ptrp r p)
-> FStar.Pervasives.Lemma
(ensures
Steel.Reference.ghost_ptr_sel' r p m0 ==
Steel.Reference.ghost_ptr_sel' r p (Steel.Memory.core_mem m0)) | {
"end_col": 51,
"end_line": 449,
"start_col": 3,
"start_line": 446
} |
FStar.Pervasives.Lemma | val pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1 | val pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
let pts_to_ref_injective (#a: Type u#0) (r: ref a) (p0 p1: perm) (v0 v1: a) (m: mem)
: Lemma (requires interp ((pts_to_sl r p0 v0) `Mem.star` (pts_to_sl r p1 v1)) m)
(ensures v0 == v1) = | false | null | true | let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1 | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.mem",
"Steel.Reference.raise_val_inj",
"Prims.unit",
"Steel.HigherReference.pts_to_ref_injective",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Steel.Memory.interp",
"Steel.Memory.star",
"Steel.Reference.pts_to_sl",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1) | [] | Steel.Reference.pts_to_ref_injective | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p0: Steel.FractionalPermission.perm ->
p1: Steel.FractionalPermission.perm ->
v0: a ->
v1: a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires
Steel.Memory.interp (Steel.Memory.star (Steel.Reference.pts_to_sl r p0 v0)
(Steel.Reference.pts_to_sl r p1 v1))
m) (ensures v0 == v1) | {
"end_col": 25,
"end_line": 58,
"start_col": 5,
"start_line": 55
} |
FStar.Pervasives.Lemma | val hide_raise_reveal (#a: Type) (v0 v1: erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==> v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0))); SMTPat (hide (U.raise_val (reveal v1)))] | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1) | val hide_raise_reveal (#a: Type) (v0 v1: erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==> v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0))); SMTPat (hide (U.raise_val (reveal v1)))]
let hide_raise_reveal (#a: Type) (v0 v1: erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==> v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0))); SMTPat (hide (U.raise_val (reveal v1)))] = | false | null | true | let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"FStar.Ghost.erased",
"Prims._assert",
"Prims.l_iff",
"Prims.eq2",
"FStar.Universe.downgrade_val",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal",
"FStar.Universe.raise_t",
"FStar.Ghost.hide",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0))); | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hide_raise_reveal (#a: Type) (v0 v1: erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==> v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0))); SMTPat (hide (U.raise_val (reveal v1)))] | [] | Steel.Reference.hide_raise_reveal | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | v0: FStar.Ghost.erased a -> v1: FStar.Ghost.erased a
-> FStar.Pervasives.Lemma
(ensures
FStar.Ghost.hide (FStar.Universe.raise_val (FStar.Ghost.reveal v0)) ==
FStar.Ghost.hide (FStar.Universe.raise_val (FStar.Ghost.reveal v1)) <==>
v0 == v1)
[
SMTPat (FStar.Ghost.hide (FStar.Universe.raise_val (FStar.Ghost.reveal v0)));
SMTPat (FStar.Ghost.hide (FStar.Universe.raise_val (FStar.Ghost.reveal v1)))
] | {
"end_col": 21,
"end_line": 147,
"start_col": 3,
"start_line": 144
} |
Steel.Effect.Atomic.SteelGhost | val ghost_free (#a:Type0) (#opened:inames) (r:ghost_ref a) : SteelGhost unit opened
(ghost_vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_free r =
let _ = elim_ghost_vptr r _ in
ghost_free_pt r | val ghost_free (#a:Type0) (#opened:inames) (r:ghost_ref a) : SteelGhost unit opened
(ghost_vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True)
let ghost_free r = | true | null | false | let _ = elim_ghost_vptr r _ in
ghost_free_pt r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"Steel.Reference.ghost_free_pt",
"Prims.unit",
"FStar.Ghost.erased",
"Steel.Reference.elim_ghost_vptr",
"Steel.FractionalPermission.full_perm"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v
let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_free (#a:Type0) (#opened:inames) (r:ghost_ref a) : SteelGhost unit opened
(ghost_vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True) | [] | Steel.Reference.ghost_free | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 17,
"end_line": 493,
"start_col": 18,
"start_line": 491
} |
Prims.Tot | val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (v:a) : slprop u#1 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x) | val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (v:a) : slprop u#1
let ghost_pts_to_sl #a r p x = | false | null | false | H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.HigherReference.ghost_pts_to_sl",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Steel.Memory.slprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (v:a) : slprop u#1 | [] | Steel.Reference.ghost_pts_to_sl | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm -> v: a -> Steel.Memory.slprop | {
"end_col": 83,
"end_line": 363,
"start_col": 31,
"start_line": 363
} |
Prims.Tot | val ghost_ref (a:Type u#0) : Type u#0 | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ref a = H.ghost_ref (U.raise_t a) | val ghost_ref (a:Type u#0) : Type u#0
let ghost_ref a = | false | null | false | H.ghost_ref (U.raise_t a) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.HigherReference.ghost_ref",
"FStar.Universe.raise_t"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *) | false | true | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ref (a:Type u#0) : Type u#0 | [] | Steel.Reference.ghost_ref | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Type0 -> Type0 | {
"end_col": 43,
"end_line": 360,
"start_col": 18,
"start_line": 360
} |
Prims.Tot | val raise_erased (#a: Type0) (x: erased a) : erased (U.raise_t u#0 u#1 a) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x)) | val raise_erased (#a: Type0) (x: erased a) : erased (U.raise_t u#0 u#1 a)
let raise_erased (#a: Type0) (x: erased a) : erased (U.raise_t u#0 u#1 a) = | false | null | false | Ghost.hide (U.raise_val (Ghost.reveal x)) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"FStar.Ghost.erased",
"FStar.Ghost.hide",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val raise_erased (#a: Type0) (x: erased a) : erased (U.raise_t u#0 u#1 a) | [] | Steel.Reference.raise_erased | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: FStar.Ghost.erased a -> FStar.Ghost.erased (FStar.Universe.raise_t a) | {
"end_col": 45,
"end_line": 377,
"start_col": 4,
"start_line": 377
} |
FStar.Pervasives.Lemma | val downgrade_equiv (#t: Type) (x y: U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==> x == y) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y) | val downgrade_equiv (#t: Type) (x y: U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==> x == y)
let downgrade_equiv (#t: Type) (x y: U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==> x == y) = | false | null | true | assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"FStar.Universe.raise_t",
"Prims._assert",
"Prims.eq2",
"FStar.Universe.raise_val",
"FStar.Universe.downgrade_val",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==> | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val downgrade_equiv (#t: Type) (x y: U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==> x == y) | [] | Steel.Reference.downgrade_equiv | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: FStar.Universe.raise_t t -> y: FStar.Universe.raise_t t
-> FStar.Pervasives.Lemma
(ensures FStar.Universe.downgrade_val x == FStar.Universe.downgrade_val y <==> x == y) | {
"end_col": 49,
"end_line": 169,
"start_col": 4,
"start_line": 168
} |
Steel.Effect.Atomic.SteelGhostT | val ghost_free_pt (#a:Type0) (#u:_) (#v:erased a) (r:ghost_ref a)
: SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_free_pt r = H.ghost_free r | val ghost_free_pt (#a:Type0) (#u:_) (#v:erased a) (r:ghost_ref a)
: SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> emp)
let ghost_free_pt r = | true | null | false | H.ghost_free r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Steel.HigherReference.ghost_free",
"FStar.Universe.raise_t",
"FStar.Ghost.hide",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_free_pt (#a:Type0) (#u:_) (#v:erased a) (r:ghost_ref a)
: SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> emp) | [] | Steel.Reference.ghost_free_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhostT Prims.unit | {
"end_col": 36,
"end_line": 385,
"start_col": 22,
"start_line": 385
} |
Prims.Tot | val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h | val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = | false | null | false | fun h -> id_elim_exists #a (pts_to_sl r p) h | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ptrp",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Steel.Reference.pts_to_sl"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p) | [] | Steel.Reference.ptr_sel' | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Common.selector' a (Steel.Reference.ptrp r p) | {
"end_col": 66,
"end_line": 245,
"start_col": 22,
"start_line": 245
} |
FStar.Pervasives.Lemma | val intro_ptrp_interp (#a:Type0) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m | val intro_ptrp_interp (#a:Type0) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m)
let intro_ptrp_interp r p v m = | false | null | true | intro_h_exists (reveal v) (pts_to_sl r p) m | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Memory.mem",
"Steel.Memory.intro_h_exists",
"FStar.Ghost.reveal",
"Steel.Reference.pts_to_sl",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_ptrp_interp (#a:Type0) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m) | [] | Steel.Reference.intro_ptrp_interp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p: Steel.FractionalPermission.perm ->
v: FStar.Ghost.erased a ->
m: Steel.Memory.mem
-> FStar.Pervasives.Lemma
(requires Steel.Memory.interp (Steel.Reference.pts_to_sl r p (FStar.Ghost.reveal v)) m)
(ensures Steel.Memory.interp (Steel.Reference.ptrp r p) m) | {
"end_col": 75,
"end_line": 271,
"start_col": 32,
"start_line": 271
} |
FStar.Pervasives.Lemma | val ptr_sel_depends_only_on_core (#a: Type0) (r: ref a) (p: perm) (m0: Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0) | val ptr_sel_depends_only_on_core (#a: Type0) (r: ref a) (p: perm) (m0: Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
let ptr_sel_depends_only_on_core (#a: Type0) (r: ref a) (p: perm) (m0: Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0)) = | false | null | true | let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.hmem",
"Steel.Reference.ptrp",
"Steel.Memory.elim_wi",
"Steel.Reference.pts_to_sl",
"Steel.Memory.core_mem",
"Prims.unit",
"Steel.Reference.pts_to_witinv",
"FStar.Ghost.reveal",
"Steel.Memory.id_elim_exists",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Steel.Reference.ptr_sel'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p)) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptr_sel_depends_only_on_core (#a: Type0) (r: ref a) (p: perm) (m0: Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0)) | [] | Steel.Reference.ptr_sel_depends_only_on_core | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ref a ->
p: Steel.FractionalPermission.perm ->
m0: Steel.Memory.hmem (Steel.Reference.ptrp r p)
-> FStar.Pervasives.Lemma
(ensures
Steel.Reference.ptr_sel' r p m0 == Steel.Reference.ptr_sel' r p (Steel.Memory.core_mem m0)) | {
"end_col": 45,
"end_line": 262,
"start_col": 3,
"start_line": 259
} |
Prims.Tot | val lift_eq (#t: eqtype) (x y: U.raise_t t) : b: bool{b <==> x == y} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y | val lift_eq (#t: eqtype) (x y: U.raise_t t) : b: bool{b <==> x == y}
let lift_eq (#t: eqtype) (x y: U.raise_t t) : b: bool{b <==> x == y} = | false | null | false | downgrade_equiv x y;
U.downgrade_val x = U.downgrade_val y | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Prims.eqtype",
"FStar.Universe.raise_t",
"Prims.op_Equality",
"FStar.Universe.downgrade_val",
"Prims.unit",
"Steel.Reference.downgrade_equiv",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lift_eq (#t: eqtype) (x y: U.raise_t t) : b: bool{b <==> x == y} | [] | Steel.Reference.lift_eq | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: FStar.Universe.raise_t t -> y: FStar.Universe.raise_t t -> b: Prims.bool{b <==> x == y} | {
"end_col": 62,
"end_line": 173,
"start_col": 4,
"start_line": 173
} |
Steel.Effect.Atomic.SteelGhostT | val ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x) | val ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
let ghost_write_pt (#a: Type) (#u: _) (#v: erased a) (r: ghost_ref a) (x: erased a)
: SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> ghost_pts_to r full_perm x) = | true | null | false | H.ghost_write r (raise_erased x) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Steel.HigherReference.ghost_write",
"FStar.Universe.raise_t",
"FStar.Ghost.hide",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal",
"Steel.Reference.raise_erased",
"Prims.unit",
"Steel.Reference.ghost_pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x) | [] | Steel.Reference.ghost_write_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> x: FStar.Ghost.erased a
-> Steel.Effect.Atomic.SteelGhostT Prims.unit | {
"end_col": 36,
"end_line": 425,
"start_col": 4,
"start_line": 425
} |
Prims.Tot | val ghost_ptrp_sel (#a:Type0) (r:ghost_ref a) (p: perm) : selector a (ghost_ptrp r p) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p | val ghost_ptrp_sel (#a:Type0) (r:ghost_ref a) (p: perm) : selector a (ghost_ptrp r p)
let ghost_ptrp_sel r p = | false | null | false | Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"total"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Reference.ghost_ptr_sel'",
"Prims.unit",
"FStar.Classical.forall_intro",
"Steel.Memory.hmem",
"Steel.Reference.ghost_ptrp",
"Prims.eq2",
"Steel.Memory.core_mem",
"Steel.Reference.ghost_ptr_sel_depends_only_on_core",
"FStar.Classical.forall_intro_2",
"Steel.Memory.mem",
"Steel.Memory.disjoint",
"Steel.Memory.join",
"Steel.Reference.ghost_ptr_sel_depends_only_on",
"Steel.Effect.Common.selector"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptrp_sel (#a:Type0) (r:ghost_ref a) (p: perm) : selector a (ghost_ptrp r p) | [] | Steel.Reference.ghost_ptrp_sel | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Common.selector a (Steel.Reference.ghost_ptrp r p) | {
"end_col": 20,
"end_line": 454,
"start_col": 2,
"start_line": 452
} |
FStar.Pervasives.Lemma | val ghost_ptrp_sel_interp (#a:Type0) (r:ghost_ref a) (p: perm) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m)
(ensures interp (ghost_pts_to_sl r p (ghost_ptrp_sel r p m)) m) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p | val ghost_ptrp_sel_interp (#a:Type0) (r:ghost_ref a) (p: perm) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m)
(ensures interp (ghost_pts_to_sl r p (ghost_ptrp_sel r p m)) m)
let ghost_ptrp_sel_interp #a r p m = | false | null | true | ghost_pts_to_witinv r p | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [
"lemma"
] | [
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.Memory.mem",
"Steel.Reference.ghost_pts_to_witinv",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_ptrp_sel_interp (#a:Type0) (r:ghost_ref a) (p: perm) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m)
(ensures interp (ghost_pts_to_sl r p (ghost_ptrp_sel r p m)) m) | [] | Steel.Reference.ghost_ptrp_sel_interp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm -> m: Steel.Memory.mem
-> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Reference.ghost_ptrp r p) m)
(ensures
Steel.Memory.interp (Steel.Reference.ghost_pts_to_sl r
p
(Steel.Reference.ghost_ptrp_sel r p m))
m) | {
"end_col": 60,
"end_line": 456,
"start_col": 37,
"start_line": 456
} |
Steel.Effect.Atomic.SteelGhost | val intro_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm) (v: erased a)
: SteelGhost unit
opened
(ghost_pts_to r p v)
(fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v) | val intro_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm) (v: erased a)
: SteelGhost unit
opened
(ghost_pts_to r p v)
(fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
let intro_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm) (v: erased a)
: SteelGhost unit
opened
(ghost_pts_to r p v)
(fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v) = | true | null | false | change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Effect.Atomic.change_slprop_2",
"Steel.Reference.ghost_pts_to",
"FStar.Ghost.reveal",
"Steel.Reference.ghost_vptrp",
"Steel.Reference.intro_ghost_vptr_lemma",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm) (v: erased a)
: SteelGhost unit
opened
(ghost_pts_to r p v)
(fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v) | [] | Steel.Reference.intro_ghost_vptr | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm -> v: FStar.Ghost.erased a
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 91,
"end_line": 475,
"start_col": 4,
"start_line": 475
} |
Steel.Effect.Atomic.SteelGhost | val intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v) | val intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
let intro_vptr (#a: Type) (#opened: inames) (r: ref a) (p: perm) (v: erased a)
: SteelGhost unit
opened
(pts_to r p v)
(fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v) = | true | null | false | change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Effect.Atomic.change_slprop_2",
"Steel.Reference.pts_to",
"FStar.Ghost.reveal",
"Steel.Reference.vptrp",
"Steel.Reference.intro_vptr_lemma",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v) | [] | Steel.Reference.intro_vptr | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> v: FStar.Ghost.erased a
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 73,
"end_line": 289,
"start_col": 4,
"start_line": 289
} |
Steel.Effect.SteelT | val free_pt (#a:Type0) (#v:erased a) (r:ref a)
: SteelT unit (pts_to r full_perm v) (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r | val free_pt (#a:Type0) (#v:erased a) (r:ref a)
: SteelT unit (pts_to r full_perm v) (fun _ -> emp)
let free_pt #a #v r = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"FStar.Ghost.erased",
"Steel.Reference.ref",
"Steel.HigherReference.free",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.HigherReference.pts_to",
"Steel.Memory.mem",
"FStar.Universe.raise_val"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ()) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val free_pt (#a:Type0) (#v:erased a) (r:ref a)
: SteelT unit (pts_to r full_perm v) (fun _ -> emp) | [] | Steel.Reference.free_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.SteelT Prims.unit | {
"end_col": 10,
"end_line": 130,
"start_col": 21,
"start_line": 127
} |
Steel.Effect.Atomic.SteelGhost | val vptrp_not_null (#opened: _)
(#a: Type)
(r: ref a)
(p: perm)
: SteelGhost unit opened
(vptrp r p)
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h0 _ h1 ->
h0 (vptrp r p) == h1 (vptrp r p) /\
is_null r == false
) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m) | val vptrp_not_null (#opened: _)
(#a: Type)
(r: ref a)
(p: perm)
: SteelGhost unit opened
(vptrp r p)
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h0 _ h1 ->
h0 (vptrp r p) == h1 (vptrp r p) /\
is_null r == false
)
let vptrp_not_null #opened #a r p = | true | null | false | change_slprop_rel (vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Effect.Atomic.change_slprop_rel",
"Steel.Reference.vptrp",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"Steel.Reference.is_null",
"Prims.prop",
"Steel.Memory.mem",
"Steel.Reference.pts_to_not_null",
"Steel.Reference.ptrp_sel",
"Prims.unit"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vptrp_not_null (#opened: _)
(#a: Type)
(r: ref a)
(p: perm)
: SteelGhost unit opened
(vptrp r p)
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h0 _ h1 ->
h0 (vptrp r p) == h1 (vptrp r p) /\
is_null r == false
) | [] | Steel.Reference.vptrp_not_null | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 53,
"end_line": 355,
"start_col": 2,
"start_line": 351
} |
Steel.Effect.Steel | val free (#a:Type0) (r:ref a) : Steel unit
(vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let free r =
let _ = elim_vptr r _ in
free_pt r | val free (#a:Type0) (r:ref a) : Steel unit
(vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True)
let free r = | true | null | false | let _ = elim_vptr r _ in
free_pt r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Reference.ref",
"Steel.Reference.free_pt",
"Prims.unit",
"FStar.Ghost.erased",
"Steel.Reference.elim_vptr",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.FractionalPermission.full_perm"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val free (#a:Type0) (r:ref a) : Steel unit
(vptr r) (fun _ -> emp)
(requires fun _ -> True)
(ensures fun _ _ _ -> True) | [] | Steel.Reference.free | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Steel Prims.unit | {
"end_col": 11,
"end_line": 306,
"start_col": 12,
"start_line": 304
} |
Steel.Effect.Atomic.SteelGhostT | val ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x) | val ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
let ghost_alloc_pt (#a: Type) (#u: _) (x: erased a)
: SteelGhostT (ghost_ref a) u emp (fun r -> ghost_pts_to r full_perm x) = | true | null | false | H.ghost_alloc (raise_erased x) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.HigherReference.ghost_alloc",
"FStar.Universe.raise_t",
"Steel.Reference.raise_erased",
"Steel.HigherReference.ghost_ref",
"Steel.Reference.ghost_ref",
"Steel.Effect.Common.emp",
"Steel.Reference.ghost_pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x) | [] | Steel.Reference.ghost_alloc_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhostT (Steel.Reference.ghost_ref a) | {
"end_col": 34,
"end_line": 383,
"start_col": 4,
"start_line": 383
} |
Steel.Effect.Atomic.SteelGhost | val pts_to_injective_eq
(#a: Type)
(#opened:inames)
(#p0 #p1:perm)
(#v0 #v1: erased a)
(r: ref a)
: SteelGhost unit opened
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) | val pts_to_injective_eq
(#a: Type)
(#opened:inames)
(#p0 #p1:perm)
(#v0 #v1: erased a)
(r: ref a)
: SteelGhost unit opened
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = | true | null | false | extract_info_raw ((pts_to r p0 v0) `star` (pts_to r p1 v1))
(v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ref",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.Reference.pts_to",
"FStar.Ghost.reveal",
"Steel.Memory.mem",
"Prims.unit",
"Steel.Effect.Atomic.extract_info_raw",
"Steel.Effect.Common.star",
"Prims.eq2",
"Steel.Reference.pts_to_ref_injective"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pts_to_injective_eq
(#a: Type)
(#opened:inames)
(#p0 #p1:perm)
(#v0 #v1: erased a)
(r: ref a)
: SteelGhost unit opened
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1) | [] | Steel.Reference.pts_to_injective_eq | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 64,
"end_line": 93,
"start_col": 2,
"start_line": 91
} |
Steel.Effect.Atomic.SteelGhost | val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1) | val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
let ghost_pts_to_injective_eq (#a #u #p #q: _) (r: ghost_ref a) (v0 v1: Ghost.erased a)
: SteelGhost unit
u
((ghost_pts_to r p v0) `star` (ghost_pts_to r q v1))
(fun _ -> (ghost_pts_to r p v0) `star` (ghost_pts_to r q v0))
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1) = | true | null | false | H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.Reference.ghost_ref",
"FStar.Ghost.erased",
"Steel.HigherReference.ghost_pts_to_injective_eq",
"FStar.Universe.raise_t",
"Steel.Reference.raise_erased",
"Prims.unit",
"Steel.Effect.Common.star",
"Steel.Reference.ghost_pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1) | [] | Steel.Reference.ghost_pts_to_injective_eq | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> v0: FStar.Ghost.erased a -> v1: FStar.Ghost.erased a
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 81,
"end_line": 411,
"start_col": 4,
"start_line": 411
} |
Steel.Effect.Atomic.SteelGhost | val ghost_read_pt (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ghost_ref a)
: SteelGhost (erased a) u (ghost_pts_to r p v) (fun x -> ghost_pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x' | val ghost_read_pt (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ghost_ref a)
: SteelGhost (erased a) u (ghost_pts_to r p v) (fun x -> ghost_pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == v)
let ghost_read_pt #a #u #p #v r = | true | null | false | let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x' | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.ghost_pts_to",
"FStar.Universe.raise_t",
"FStar.Ghost.reveal",
"Steel.Reference.ghost_pts_to",
"Steel.Memory.mem",
"FStar.Ghost.hide",
"FStar.Universe.downgrade_val",
"Steel.HigherReference.ghost_read",
"FStar.Universe.raise_val"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_read_pt (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ghost_ref a)
: SteelGhost (erased a) u (ghost_pts_to r p v) (fun x -> ghost_pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == v) | [] | Steel.Reference.ghost_read_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased a) | {
"end_col": 4,
"end_line": 419,
"start_col": 33,
"start_line": 415
} |
Steel.Effect.Atomic.SteelGhost | val gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p) | val gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit
uses
((vptrp r (half_perm p)) `star` (vptrp r (half_perm p)))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' -> h' (vptrp r p) == h (vptrp r (half_perm p))) = | true | null | false | let _ = gather_gen r _ _ in
change_equal_slprop (vptrp r _) (vptrp r p) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.Reference.ref",
"Steel.Effect.Atomic.change_equal_slprop",
"Steel.Reference.vptrp",
"Prims.unit",
"Steel.Reference.gather_gen",
"Steel.FractionalPermission.half_perm",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p)) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
) | [] | Steel.Reference.gather | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 17,
"end_line": 344,
"start_col": 3,
"start_line": 341
} |
Steel.Effect.Atomic.SteelGhost | val ghost_write (#a:Type0) (#opened:inames) (r:ghost_ref a) (x:Ghost.erased a)
: SteelGhost unit opened
(ghost_vptr r) (fun _ -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> Ghost.reveal x == h1 (ghost_vptr r)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_write r x =
let _ = elim_ghost_vptr r _ in
ghost_write_pt r x;
intro_ghost_vptr r _ x | val ghost_write (#a:Type0) (#opened:inames) (r:ghost_ref a) (x:Ghost.erased a)
: SteelGhost unit opened
(ghost_vptr r) (fun _ -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> Ghost.reveal x == h1 (ghost_vptr r))
let ghost_write r x = | true | null | false | let _ = elim_ghost_vptr r _ in
ghost_write_pt r x;
intro_ghost_vptr r _ x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"FStar.Ghost.erased",
"Steel.Reference.intro_ghost_vptr",
"Steel.FractionalPermission.full_perm",
"Prims.unit",
"Steel.Reference.ghost_write_pt",
"Steel.Reference.elim_ghost_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v
let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r
let ghost_free r =
let _ = elim_ghost_vptr r _ in
ghost_free_pt r
let ghost_readp r _ =
let _ = elim_ghost_vptr r _ in
let x = ghost_read_pt r in
intro_ghost_vptr r _ x;
x | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_write (#a:Type0) (#opened:inames) (r:ghost_ref a) (x:Ghost.erased a)
: SteelGhost unit opened
(ghost_vptr r) (fun _ -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> Ghost.reveal x == h1 (ghost_vptr r)) | [] | Steel.Reference.ghost_write | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> x: FStar.Ghost.erased a
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 24,
"end_line": 504,
"start_col": 21,
"start_line": 501
} |
Steel.Effect.Steel | val alloc_pt (#a:Type) (x:a)
: Steel (ref a) emp (fun r -> pts_to r full_perm x)
(requires fun _ -> True)
(ensures fun _ r _ -> not (is_null r)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r | val alloc_pt (#a:Type) (x:a)
: Steel (ref a) emp (fun r -> pts_to r full_perm x)
(requires fun _ -> True)
(ensures fun _ r _ -> not (is_null r))
let alloc_pt x = | true | null | false | let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Effect.Atomic.return",
"Steel.Reference.ref",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val",
"Steel.Memory.mem",
"Steel.HigherReference.ref",
"Steel.HigherReference.alloc"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val alloc_pt (#a:Type) (x:a)
: Steel (ref a) emp (fun r -> pts_to r full_perm x)
(requires fun _ -> True)
(ensures fun _ r _ -> not (is_null r)) | [] | Steel.Reference.alloc_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> Steel.Effect.Steel (Steel.Reference.ref a) | {
"end_col": 10,
"end_line": 98,
"start_col": 16,
"start_line": 95
} |
Steel.Effect.Steel | val malloc (#a:Type0) (x:a) : Steel (ref a)
emp (fun r -> vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> sel r h1 == x /\ not (is_null r)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r | val malloc (#a:Type0) (x:a) : Steel (ref a)
emp (fun r -> vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> sel r h1 == x /\ not (is_null r))
let malloc x = | true | null | false | let r = alloc_pt x in
intro_vptr r _ (hide x);
return r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Effect.Atomic.return",
"Steel.Reference.ref",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Reference.vptrp",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Reference.intro_vptr",
"Steel.Reference.alloc_pt"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val malloc (#a:Type0) (x:a) : Steel (ref a)
emp (fun r -> vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> sel r h1 == x /\ not (is_null r)) | [] | Steel.Reference.malloc | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> Steel.Effect.Steel (Steel.Reference.ref a) | {
"end_col": 10,
"end_line": 302,
"start_col": 14,
"start_line": 299
} |
Steel.Effect.Atomic.SteelGhost | val ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r | val ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
let ghost_gather_pt (#a: Type) (#u: _) (#p0 #p1: perm) (#x0 #x1: erased a) (r: ghost_ref a)
: SteelGhost unit
u
((ghost_pts_to r p0 x0) `star` (ghost_pts_to r p1 x1))
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1) = | true | null | false | H.ghost_gather r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Steel.HigherReference.ghost_gather",
"FStar.Universe.raise_t",
"FStar.Ghost.hide",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal",
"Prims.unit",
"Steel.Effect.Common.star",
"Steel.Reference.ghost_pts_to",
"Steel.FractionalPermission.sum_perm",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.b2t",
"Prims.eq2"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1) | [] | Steel.Reference.ghost_gather_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 20,
"end_line": 403,
"start_col": 4,
"start_line": 403
} |
Steel.Effect.Atomic.SteelAtomicT | val atomic_write_pt_u32 (#opened:_) (#v:erased U32.t) (r:ref U32.t) (x:U32.t)
: SteelAtomicT unit opened
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ()) | val atomic_write_pt_u32 (#opened:_) (#v:erased U32.t) (r:ref U32.t) (x:U32.t)
: SteelAtomicT unit opened
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x)
let atomic_write_pt_u32 #_ #v r x = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ()) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"FStar.UInt32.t",
"Steel.Reference.ref",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"Steel.FractionalPermission.full_perm",
"Steel.Reference.pts_to",
"Steel.Memory.mem",
"Prims.unit",
"Steel.HigherReference.atomic_write",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal",
"FStar.Ghost.hide"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val atomic_write_pt_u32 (#opened:_) (#v:erased U32.t) (r:ref U32.t) (x:U32.t)
: SteelAtomicT unit opened
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x) | [] | Steel.Reference.atomic_write_pt_u32 | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref FStar.UInt32.t -> x: FStar.UInt32.t
-> Steel.Effect.Atomic.SteelAtomicT Prims.unit | {
"end_col": 86,
"end_line": 218,
"start_col": 35,
"start_line": 213
} |
Steel.Effect.Steel | val write (#a:Type0) (r:ref a) (x:a) : Steel unit
(vptr r) (fun _ -> vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> x == sel r h1) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x | val write (#a:Type0) (r:ref a) (x:a) : Steel unit
(vptr r) (fun _ -> vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> x == sel r h1)
let write r x = | true | null | false | let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Reference.ref",
"Steel.Reference.intro_vptr",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.FractionalPermission.full_perm",
"Prims.unit",
"Steel.Reference.write_pt",
"FStar.Ghost.erased",
"Steel.Reference.elim_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write (#a:Type0) (r:ref a) (x:a) : Steel unit
(vptr r) (fun _ -> vptr r)
(requires fun _ -> True)
(ensures fun _ _ h1 -> x == sel r h1) | [] | Steel.Reference.write | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> x: a -> Steel.Effect.Steel Prims.unit | {
"end_col": 18,
"end_line": 317,
"start_col": 15,
"start_line": 314
} |
Steel.Effect.Atomic.SteelGhost | val ghost_alloc (#a:Type0) (#opened:inames) (x:Ghost.erased a)
: SteelGhost (ghost_ref a) opened
emp (fun r -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> ghost_sel r h1 == Ghost.reveal x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r | val ghost_alloc (#a:Type0) (#opened:inames) (x:Ghost.erased a)
: SteelGhost (ghost_ref a) opened
emp (fun r -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> ghost_sel r h1 == Ghost.reveal x)
let ghost_alloc x = | true | null | false | let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.Reference.ghost_ref",
"Prims.unit",
"Steel.Reference.intro_ghost_vptr",
"Steel.FractionalPermission.full_perm",
"Steel.Reference.ghost_alloc_pt"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_alloc (#a:Type0) (#opened:inames) (x:Ghost.erased a)
: SteelGhost (ghost_ref a) opened
emp (fun r -> ghost_vptr r)
(requires fun _ -> True)
(ensures fun _ r h1 -> ghost_sel r h1 == Ghost.reveal x) | [] | Steel.Reference.ghost_alloc | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhost (Steel.Reference.ghost_ref a) | {
"end_col": 3,
"end_line": 489,
"start_col": 19,
"start_line": 486
} |
Steel.Effect.SteelT | val write_pt (#a:Type0) (#v:erased a) (r:ref a) (x:a)
: SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ()) | val write_pt (#a:Type0) (#v:erased a) (r:ref a) (x:a)
: SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
let write_pt #a #v r x = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ()) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"FStar.Ghost.erased",
"Steel.Reference.ref",
"Steel.Effect.Atomic.rewrite_slprop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"Steel.FractionalPermission.full_perm",
"Steel.Reference.pts_to",
"Steel.Memory.mem",
"Prims.unit",
"Steel.HigherReference.write",
"FStar.Universe.raise_val",
"FStar.Ghost.reveal"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_pt (#a:Type0) (#v:erased a) (r:ref a) (x:a)
: SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) | [] | Steel.Reference.write_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> x: a -> Steel.Effect.SteelT Prims.unit | {
"end_col": 86,
"end_line": 125,
"start_col": 24,
"start_line": 120
} |
Steel.Effect.Atomic.SteelGhost | val ghost_readp (#a:Type0) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (Ghost.erased a) opened
(ghost_vptrp r p) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (ghost_vptrp r p) == h1 (ghost_vptrp r p) /\ Ghost.reveal x == h1 (ghost_vptrp r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_readp r _ =
let _ = elim_ghost_vptr r _ in
let x = ghost_read_pt r in
intro_ghost_vptr r _ x;
x | val ghost_readp (#a:Type0) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (Ghost.erased a) opened
(ghost_vptrp r p) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (ghost_vptrp r p) == h1 (ghost_vptrp r p) /\ Ghost.reveal x == h1 (ghost_vptrp r p))
let ghost_readp r _ = | true | null | false | let _ = elim_ghost_vptr r _ in
let x = ghost_read_pt r in
intro_ghost_vptr r _ x;
x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Prims.unit",
"Steel.Reference.intro_ghost_vptr",
"Steel.Reference.ghost_read_pt",
"Steel.Reference.elim_ghost_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v
let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r
let ghost_free r =
let _ = elim_ghost_vptr r _ in
ghost_free_pt r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_readp (#a:Type0) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (Ghost.erased a) opened
(ghost_vptrp r p) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (ghost_vptrp r p) == h1 (ghost_vptrp r p) /\ Ghost.reveal x == h1 (ghost_vptrp r p)) | [] | Steel.Reference.ghost_readp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased a) | {
"end_col": 3,
"end_line": 499,
"start_col": 21,
"start_line": 495
} |
Steel.Effect.Atomic.SteelGhost | val elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v | val elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
let elim_vptr (#a: Type) (#opened: inames) (r: ref a) (p: perm)
: SteelGhost (erased a)
opened
(vptrp r p)
(fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p)) = | true | null | false | let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Prims.unit",
"Steel.Effect.Atomic.change_slprop",
"Steel.Reference.vptrp",
"Steel.Reference.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.t_of",
"FStar.Ghost.hide",
"Steel.Effect.Common.normal",
"Steel.Reference.elim_vptr_lemma",
"Steel.Effect.Common.VUnit",
"Steel.Reference.vptr'",
"Steel.Effect.Atomic.gget",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p)) | [] | Steel.Reference.elim_vptr | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased a) | {
"end_col": 5,
"end_line": 297,
"start_col": 3,
"start_line": 295
} |
Steel.Effect.Atomic.SteelGhost | val elim_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm)
: SteelGhost (erased a)
opened
(ghost_vptrp r p)
(fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v | val elim_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm)
: SteelGhost (erased a)
opened
(ghost_vptrp r p)
(fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
let elim_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm)
: SteelGhost (erased a)
opened
(ghost_vptrp r p)
(fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p)) = | true | null | false | let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Prims.unit",
"Steel.Effect.Atomic.change_slprop",
"Steel.Reference.ghost_vptrp",
"Steel.Reference.ghost_pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.t_of",
"FStar.Ghost.hide",
"Steel.Effect.Common.normal",
"Steel.Reference.elim_ghost_vptr_lemma",
"Steel.Effect.Common.VUnit",
"Steel.Reference.ghost_vptr'",
"Steel.Effect.Atomic.gget",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True) | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_ghost_vptr (#a: Type) (#opened: inames) (r: ghost_ref a) (p: perm)
: SteelGhost (erased a)
opened
(ghost_vptrp r p)
(fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p)) | [] | Steel.Reference.elim_ghost_vptr | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased a) | {
"end_col": 5,
"end_line": 484,
"start_col": 3,
"start_line": 482
} |
Steel.Effect.Atomic.SteelGhost | val ghost_share (#a:Type0) (#uses:_) (#p: perm) (r:ghost_ref a)
: SteelGhost unit uses
(ghost_vptrp r p)
(fun _ -> ghost_vptrp r (half_perm p) `star` ghost_vptrp r (half_perm p))
(fun _ -> True)
(fun h res h' ->
h' (ghost_vptrp r (half_perm p)) == h (ghost_vptrp r p)
) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_share #a #_ #p r =
let x = elim_ghost_vptr r p in
ghost_share_pt r;
intro_ghost_vptr r _ x;
intro_ghost_vptr r _ x | val ghost_share (#a:Type0) (#uses:_) (#p: perm) (r:ghost_ref a)
: SteelGhost unit uses
(ghost_vptrp r p)
(fun _ -> ghost_vptrp r (half_perm p) `star` ghost_vptrp r (half_perm p))
(fun _ -> True)
(fun h res h' ->
h' (ghost_vptrp r (half_perm p)) == h (ghost_vptrp r p)
)
let ghost_share #a #_ #p r = | true | null | false | let x = elim_ghost_vptr r p in
ghost_share_pt r;
intro_ghost_vptr r _ x;
intro_ghost_vptr r _ x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.Reference.ghost_ref",
"Steel.Reference.intro_ghost_vptr",
"Steel.FractionalPermission.half_perm",
"Prims.unit",
"Steel.Reference.ghost_share_pt",
"FStar.Ghost.erased",
"Steel.Reference.elim_ghost_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v
let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r
let ghost_free r =
let _ = elim_ghost_vptr r _ in
ghost_free_pt r
let ghost_readp r _ =
let _ = elim_ghost_vptr r _ in
let x = ghost_read_pt r in
intro_ghost_vptr r _ x;
x
let ghost_write r x =
let _ = elim_ghost_vptr r _ in
ghost_write_pt r x;
intro_ghost_vptr r _ x | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_share (#a:Type0) (#uses:_) (#p: perm) (r:ghost_ref a)
: SteelGhost unit uses
(ghost_vptrp r p)
(fun _ -> ghost_vptrp r (half_perm p) `star` ghost_vptrp r (half_perm p))
(fun _ -> True)
(fun h res h' ->
h' (ghost_vptrp r (half_perm p)) == h (ghost_vptrp r p)
) | [] | Steel.Reference.ghost_share | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 24,
"end_line": 510,
"start_col": 28,
"start_line": 506
} |
Steel.Effect.Atomic.SteelAtomic | val atomic_read_pt_u32 (#opened:_) (#p:perm) (#v:erased U32.t) (r:ref U32.t)
: SteelAtomic U32.t opened
(pts_to r p v)
(fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | val atomic_read_pt_u32 (#opened:_) (#p:perm) (#v:erased U32.t) (r:ref U32.t)
: SteelAtomic U32.t opened
(pts_to r p v)
(fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v)
let atomic_read_pt_u32 #_ #p #v r = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.UInt32.t",
"Steel.Reference.ref",
"Steel.Effect.Atomic.return",
"Steel.Reference.pts_to",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"Steel.Memory.mem",
"FStar.Universe.downgrade_val",
"Steel.HigherReference.atomic_read",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"FStar.Universe.raise_val"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val atomic_read_pt_u32 (#opened:_) (#p:perm) (#v:erased U32.t) (r:ref U32.t)
: SteelAtomic U32.t opened
(pts_to r p v)
(fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v) | [] | Steel.Reference.atomic_read_pt_u32 | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref FStar.UInt32.t -> Steel.Effect.Atomic.SteelAtomic FStar.UInt32.t | {
"end_col": 11,
"end_line": 211,
"start_col": 35,
"start_line": 205
} |
Steel.Effect.Atomic.SteelGhostT | val share_pt (#a:Type0) (#uses:_) (#p:perm) (#v:erased a) (r:ref a)
: SteelGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ()) | val share_pt (#a:Type0) (#uses:_) (#p:perm) (#v:erased a) (r:ref a)
: SteelGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
let share_pt #a #uses #p #v r = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ()) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ref",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"Steel.FractionalPermission.half_perm",
"FStar.Ghost.reveal",
"Steel.Reference.pts_to",
"Steel.Memory.mem",
"Prims.unit",
"Steel.HigherReference.share",
"FStar.Ghost.hide",
"FStar.Universe.raise_val"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val share_pt (#a:Type0) (#uses:_) (#p:perm) (#v:erased a) (r:ref a)
: SteelGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) | [] | Steel.Reference.share_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Atomic.SteelGhostT Prims.unit | {
"end_col": 87,
"end_line": 137,
"start_col": 31,
"start_line": 132
} |
Steel.Effect.Steel | val readp (#a:Type0) (r:ref a) (p: perm) : Steel a
(vptrp r p) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (vptrp r p) == h1 (vptrp r p) /\ x == h1 (vptrp r p)) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x | val readp (#a:Type0) (r:ref a) (p: perm) : Steel a
(vptrp r p) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (vptrp r p) == h1 (vptrp r p) /\ x == h1 (vptrp r p))
let readp r _ = | true | null | false | let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Reference.ref",
"Steel.FractionalPermission.perm",
"Steel.Effect.Atomic.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Reference.vptrp",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Reference.intro_vptr",
"Steel.Reference.read_pt",
"FStar.Ghost.erased",
"Steel.Reference.elim_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val readp (#a:Type0) (r:ref a) (p: perm) : Steel a
(vptrp r p) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun h0 x h1 -> h0 (vptrp r p) == h1 (vptrp r p) /\ x == h1 (vptrp r p)) | [] | Steel.Reference.readp | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> p: Steel.FractionalPermission.perm -> Steel.Effect.Steel a | {
"end_col": 10,
"end_line": 312,
"start_col": 15,
"start_line": 308
} |
Steel.Effect.Steel | val read_pt (#a:Type) (#p:perm) (#v:erased a) (r:ref a)
: Steel a (pts_to r p v) (fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | val read_pt (#a:Type) (#p:perm) (#v:erased a) (r:ref a)
: Steel a (pts_to r p v) (fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v)
let read_pt #a #p #v r = | true | null | false | let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.Reference.ref",
"Steel.Effect.Atomic.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Reference.pts_to",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"Steel.Memory.mem",
"FStar.Universe.downgrade_val",
"Steel.HigherReference.read",
"FStar.Ghost.reveal",
"FStar.Universe.raise_val"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_pt (#a:Type) (#p:perm) (#v:erased a) (r:ref a)
: Steel a (pts_to r p v) (fun x -> pts_to r p x)
(requires fun _ -> True)
(ensures fun _ x _ -> x == Ghost.reveal v) | [] | Steel.Reference.read_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Steel a | {
"end_col": 11,
"end_line": 106,
"start_col": 24,
"start_line": 100
} |
Steel.Effect.Atomic.SteelGhost | val share (#a:Type0) (#uses:_) (#p: perm) (r:ref a)
: SteelGhost unit uses
(vptrp r p)
(fun _ -> vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r (half_perm p)) == h (vptrp r p)
) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x | val share (#a:Type0) (#uses:_) (#p: perm) (r:ref a)
: SteelGhost unit uses
(vptrp r p)
(fun _ -> vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r (half_perm p)) == h (vptrp r p)
)
let share #a #_ #p r = | true | null | false | let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.Reference.ref",
"Steel.Reference.intro_vptr",
"Steel.FractionalPermission.half_perm",
"Prims.unit",
"Steel.Reference.share_pt",
"FStar.Ghost.erased",
"Steel.Reference.elim_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val share (#a:Type0) (#uses:_) (#p: perm) (r:ref a)
: SteelGhost unit uses
(vptrp r p)
(fun _ -> vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r (half_perm p)) == h (vptrp r p)
) | [] | Steel.Reference.share | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.Reference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 18,
"end_line": 323,
"start_col": 22,
"start_line": 319
} |
Steel.Effect.Atomic.SteelGhost | val ghost_gather_gen (#a:Type0) (#uses:_) (r:ghost_ref a) (p0:perm) (p1:perm)
: SteelGhost perm uses
(ghost_vptrp r p0 `star` ghost_vptrp r p1)
(fun res -> ghost_vptrp r res)
(fun _ -> True)
(fun h res h' ->
res == sum_perm p0 p1 /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p0) /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p1)
) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_gather_gen #a #_ r p0 p1 =
let x1 = elim_ghost_vptr r p1 in
let x0 = elim_ghost_vptr r p0 in
ghost_gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_ghost_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1 | val ghost_gather_gen (#a:Type0) (#uses:_) (r:ghost_ref a) (p0:perm) (p1:perm)
: SteelGhost perm uses
(ghost_vptrp r p0 `star` ghost_vptrp r p1)
(fun res -> ghost_vptrp r res)
(fun _ -> True)
(fun h res h' ->
res == sum_perm p0 p1 /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p0) /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p1)
)
let ghost_gather_gen #a #_ r p0 p1 = | true | null | false | let x1 = elim_ghost_vptr r p1 in
let x0 = elim_ghost_vptr r p0 in
ghost_gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_ghost_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1 | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.Memory.inames",
"Steel.Reference.ghost_ref",
"Steel.FractionalPermission.perm",
"Steel.FractionalPermission.sum_perm",
"Prims.unit",
"Steel.Reference.intro_ghost_vptr",
"Steel.Reference.ghost_gather_pt",
"FStar.Ghost.erased",
"Steel.Reference.elim_ghost_vptr"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x)
let write_pt #a #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let free_pt #a #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
H.free r
let share_pt #a #uses #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
H.share r;
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ());
rewrite_slprop (H.pts_to r (half_perm p) v') (pts_to r (half_perm p) v) (fun _ -> ())
let hide_raise_reveal (#a:Type) (v0:erased a) (v1:erased a)
: Lemma (hide (U.raise_val (reveal v0)) == hide (U.raise_val (reveal v1)) <==>
v0 == v1)
[SMTPat (hide (U.raise_val (reveal v0)));
SMTPat (hide (U.raise_val (reveal v1)))]
= let u0 = hide (U.raise_val (reveal v0)) in
let u1 = hide (U.raise_val (reveal v1)) in
assert (U.downgrade_val (U.raise_val (reveal v0)) == U.downgrade_val (U.raise_val (reveal v1)) <==>
v0 == v1)
let gather_pt #a #uses #p0 #p1 #v0 #v1 r =
let v0' = Ghost.hide (U.raise_val (Ghost.reveal v0)) in
let v1' = Ghost.hide (U.raise_val (Ghost.reveal v1)) in
rewrite_slprop (pts_to r p0 v0) (H.pts_to r p0 v0') (fun _ -> ());
rewrite_slprop (pts_to r p1 v1) (H.pts_to r p1 v1') (fun _ -> ());
let (u:unit{v0' == v1'}) = H.gather #_ #_ #p0 #p1 #v0' #v1' r in
rewrite_slprop (H.pts_to r (sum_perm p0 p1) v0') (pts_to r (sum_perm p0 p1) v0) (fun _ -> ());
u
let raise_equiv (#t:Type) (x y:t)
: Lemma (U.raise_val x == U.raise_val y <==>
x == y)
= assert (U.downgrade_val (U.raise_val x) == x);
assert (U.downgrade_val (U.raise_val y) == y)
let downgrade_equiv (#t:Type) (x y:U.raise_t t)
: Lemma (U.downgrade_val x == U.downgrade_val y <==>
x == y)
= assert (U.raise_val (U.downgrade_val x) == x);
assert (U.raise_val (U.downgrade_val y) == y)
let lift_eq (#t:eqtype) (x y:U.raise_t t)
: b:bool{b <==> x==y}
= downgrade_equiv x y; U.downgrade_val x = U.downgrade_val y
let cas_action (#t:eqtype)
(#uses:inames)
(r:ref t)
(v:Ghost.erased t)
(v_old:t)
(v_new:t)
(frame:slprop)
: MstTot (b:bool{b <==> (Ghost.reveal v == v_old)})
uses
(pts_to_sl r full_perm v)
(fun b -> if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v)
frame
(fun _ -> True)
(fun _ _ _ -> True)
= let hv = (Ghost.hide (U.raise_val (Ghost.reveal v))) in
let b = H.cas_action #(U.raise_t t)
(lift_eq #t)
#uses
r
hv
(U.raise_val v_old)
(U.raise_val v_new)
frame
in
assert (b <==> (Ghost.reveal hv == U.raise_val v_old));
assert (b <==> U.raise_val (Ghost.reveal v) == U.raise_val v_old);
raise_equiv (Ghost.reveal v) v_old;
b
let atomic_read_pt_u32 #_ #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.atomic_read r in
let v':U32.t = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v'
let atomic_write_pt_u32 #_ #v r x =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r full_perm v) (H.pts_to r full_perm v') (fun _ -> ());
let x' = U.raise_val x in
H.atomic_write r x';
rewrite_slprop (H.pts_to r full_perm (hide x')) (pts_to r full_perm x) (fun _ -> ())
let cas_pt_u32 #uses r v v_old v_new =
let b = as_atomic_action (cas_action #U32.t #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
let cas_pt_bool #uses r v v_old v_new =
let b = as_atomic_action (cas_action #bool #uses r v v_old v_new) in
rewrite_slprop (to_vprop (if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v))
(if b then pts_to r full_perm v_new else pts_to r full_perm v)
(fun _ -> ());
return b
(* Library for references with fractional permissions.
Permissions need to be an index of the vprop ptr.
It cannot be part of a selector, as it is not invariant when joining with a disjoint memory
Using the value of the ref as a selector is ok because refs with fractional permissions
all share the same value.
Refs on PCM are more complicated, and likely not usable with selectors
*)
let ptrp r p = Mem.h_exists (pts_to_sl r p)
val ptr_sel' (#a:Type0) (r: ref a) (p: perm) : selector' a (ptrp r p)
let ptr_sel' #a r p = fun h -> id_elim_exists #a (pts_to_sl r p) h
let ptr_sel_depends_only_on (#a:Type0) (r:ref a)
(p: perm)
(m0:Mem.hmem (ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (Mem.join m0 m1)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (Mem.join m0 m1)
let ptr_sel_depends_only_on_core (#a:Type0) (r:ref a)
(p: perm) (m0:Mem.hmem (ptrp r p))
: Lemma (ptr_sel' r p m0 == ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (pts_to_sl r p) (core_mem m0)) in
pts_to_witinv r p;
elim_wi (pts_to_sl r p) x y (core_mem m0)
let ptrp_sel r p =
Classical.forall_intro_2 (ptr_sel_depends_only_on r p);
Classical.forall_intro (ptr_sel_depends_only_on_core r p);
ptr_sel' r p
let ptrp_sel_interp #a r p m = pts_to_witinv r p
let intro_ptrp_interp r p v m = intro_h_exists (reveal v) (pts_to_sl r p) m
let intro_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (pts_to_sl r p v) m)
(ensures interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (pts_to_sl r p) m;
pts_to_witinv r p
let elim_vptr_lemma (#a:Type) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ptrp r p) m /\ ptrp_sel r p m == reveal v)
(ensures interp (pts_to_sl r p v) m)
= Mem.elim_h_exists (pts_to_sl r p) m;
pts_to_witinv r p
let intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v)
= change_slprop_2 (pts_to r p v) (vptrp r p) v (intro_vptr_lemma r p v)
let elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm)
: SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (vptrp r p))
= let v = gget (vptrp r p) in
change_slprop (vptrp r p) (pts_to r p v) v () (elim_vptr_lemma r p v);
v
let malloc x =
let r = alloc_pt x in
intro_vptr r _ (hide x);
return r
let free r =
let _ = elim_vptr r _ in
free_pt r
let readp r _ =
let _ = elim_vptr r _ in
let x = read_pt r in
intro_vptr r _ x;
return x
let write r x =
let _ = elim_vptr r _ in
write_pt r x;
intro_vptr r _ x
let share #a #_ #p r =
let x = elim_vptr r p in
share_pt r;
intro_vptr r _ x;
intro_vptr r _ x
let gather_gen #a #_ r p0 p1 =
let x1 = elim_vptr r p1 in
let x0 = elim_vptr r p0 in
gather_pt #_ #_ #p0 #p1 #x0 #x1 r;
intro_vptr r (sum_perm p0 p1) x0;
sum_perm p0 p1
let gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a)
: SteelGhost unit uses
(vptrp r (half_perm p) `star` vptrp r (half_perm p))
(fun _ -> vptrp r p)
(fun _ -> True)
(fun h _ h' ->
h' (vptrp r p) == h (vptrp r (half_perm p))
)
= let _ = gather_gen r _ _ in
change_equal_slprop
(vptrp r _)
(vptrp r p)
(*** Lemmas on references *)
let vptrp_not_null
#opened #a r
p
= change_slprop_rel
(vptrp r p)
(vptrp r p)
(fun x y -> x == y /\ is_null r == false)
(fun m -> pts_to_not_null r p (ptrp_sel r p m) m)
(*** Ghost pointers *)
(*** GHOST REFERENCES ***)
let ghost_ref a = H.ghost_ref (U.raise_t a)
[@__reduce__]
let ghost_pts_to_sl #a r p x = H.ghost_pts_to_sl #(U.raise_t a) r p (U.raise_val x)
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m))
(ensures (x == y))
= H.ghost_pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
[@@__reduce__]
let raise_erased (#a:Type0) (x:erased a)
: erased (U.raise_t u#0 u#1 a)
= Ghost.hide (U.raise_val (Ghost.reveal x))
let ghost_alloc_pt (#a:Type) (#u:_) (x:erased a)
: SteelGhostT (ghost_ref a) u
emp
(fun r -> ghost_pts_to r full_perm x)
= H.ghost_alloc (raise_erased x)
let ghost_free_pt r = H.ghost_free r
let ghost_share_pt (#a:Type) (#u:_)
(#p:perm)
(#x:erased a)
(r:ghost_ref a)
= H.ghost_share #_ #_ #_ #(raise_erased x) r
let ghost_gather_pt (#a:Type) (#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ghost_ref a)
: SteelGhost unit u
(ghost_pts_to r p0 x0 `star`
ghost_pts_to r p1 x1)
(fun _ -> ghost_pts_to r (sum_perm p0 p1) x0)
(requires fun _ -> true)
(ensures fun _ _ _ -> x0 == x1)
= H.ghost_gather r
let ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a)
: SteelGhost unit u
(ghost_pts_to r p v0 `star` ghost_pts_to r q v1)
(fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0)
(requires fun _ -> True)
(ensures fun _ _ _ -> v0 == v1)
= H.ghost_pts_to_injective_eq #_ #_ #p #q r (raise_erased v0) (raise_erased v1)
let ghost_pts_to_perm r = H.ghost_pts_to_perm r
let ghost_read_pt #a #u #p #v r =
let x = H.ghost_read r in
let x' = hide (U.downgrade_val (reveal x)) in
rewrite_slprop (H.ghost_pts_to r p x) (ghost_pts_to r p x') (fun _ -> ());
x'
let ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a)
: SteelGhostT unit u
(ghost_pts_to r full_perm v)
(fun _ -> ghost_pts_to r full_perm x)
= H.ghost_write r (raise_erased x)
(* Selector version of ghost pointers *)
let ghost_ptrp r p = Mem.h_exists (ghost_pts_to_sl r p)
val ghost_ptr_sel' (#a:Type0) (r: ghost_ref a) (p: perm) : selector' a (ghost_ptrp r p)
let ghost_ptr_sel' #a r p = fun h -> id_elim_exists #a (ghost_pts_to_sl r p) h
let ghost_ptr_sel_depends_only_on (#a:Type0) (r:ghost_ref a)
(p: perm)
(m0:Mem.hmem (ghost_ptrp r p)) (m1:mem{disjoint m0 m1})
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (Mem.join m0 m1))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (Mem.join m0 m1)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (Mem.join m0 m1)
let ghost_ptr_sel_depends_only_on_core (#a:Type0) (r:ghost_ref a)
(p: perm) (m0:Mem.hmem (ghost_ptrp r p))
: Lemma (ghost_ptr_sel' r p m0 == ghost_ptr_sel' r p (core_mem m0))
= let x = reveal (id_elim_exists #a (ghost_pts_to_sl r p) m0) in
let y = reveal (id_elim_exists #a (ghost_pts_to_sl r p) (core_mem m0)) in
ghost_pts_to_witinv r p;
elim_wi (ghost_pts_to_sl r p) x y (core_mem m0)
let ghost_ptrp_sel r p =
Classical.forall_intro_2 (ghost_ptr_sel_depends_only_on r p);
Classical.forall_intro (ghost_ptr_sel_depends_only_on_core r p);
ghost_ptr_sel' r p
let ghost_ptrp_sel_interp #a r p m = ghost_pts_to_witinv r p
let intro_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_pts_to_sl r p v) m)
(ensures interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
= Mem.intro_h_exists (reveal v) (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let elim_ghost_vptr_lemma (#a:Type) (r:ghost_ref a) (p: perm) (v:erased a) (m:mem) : Lemma
(requires interp (ghost_ptrp r p) m /\ ghost_ptrp_sel r p m == reveal v)
(ensures interp (ghost_pts_to_sl r p v) m)
= Mem.elim_h_exists (ghost_pts_to_sl r p) m;
ghost_pts_to_witinv r p
let intro_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a) (p: perm) (v:erased a)
: SteelGhost unit opened (ghost_pts_to r p v) (fun _ -> ghost_vptrp r p)
(requires fun _ -> True)
(ensures fun _ _ h1 -> h1 (ghost_vptrp r p) == reveal v)
= change_slprop_2 (ghost_pts_to r p v) (ghost_vptrp r p) v (intro_ghost_vptr_lemma r p v)
let elim_ghost_vptr (#a:Type) (#opened:inames) (r:ghost_ref a)
(p: perm)
: SteelGhost (erased a) opened (ghost_vptrp r p) (fun v -> ghost_pts_to r p v)
(requires fun _ -> True)
(ensures fun h0 v _ -> reveal v == h0 (ghost_vptrp r p))
= let v = gget (ghost_vptrp r p) in
change_slprop (ghost_vptrp r p) (ghost_pts_to r p v) v () (elim_ghost_vptr_lemma r p v);
v
let ghost_alloc x =
let r = ghost_alloc_pt x in
intro_ghost_vptr r _ x;
r
let ghost_free r =
let _ = elim_ghost_vptr r _ in
ghost_free_pt r
let ghost_readp r _ =
let _ = elim_ghost_vptr r _ in
let x = ghost_read_pt r in
intro_ghost_vptr r _ x;
x
let ghost_write r x =
let _ = elim_ghost_vptr r _ in
ghost_write_pt r x;
intro_ghost_vptr r _ x
let ghost_share #a #_ #p r =
let x = elim_ghost_vptr r p in
ghost_share_pt r;
intro_ghost_vptr r _ x;
intro_ghost_vptr r _ x | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_gather_gen (#a:Type0) (#uses:_) (r:ghost_ref a) (p0:perm) (p1:perm)
: SteelGhost perm uses
(ghost_vptrp r p0 `star` ghost_vptrp r p1)
(fun res -> ghost_vptrp r res)
(fun _ -> True)
(fun h res h' ->
res == sum_perm p0 p1 /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p0) /\
h' (ghost_vptrp r res) == h (ghost_vptrp r p1)
) | [] | Steel.Reference.ghost_gather_gen | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Steel.Reference.ghost_ref a ->
p0: Steel.FractionalPermission.perm ->
p1: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost Steel.FractionalPermission.perm | {
"end_col": 16,
"end_line": 517,
"start_col": 36,
"start_line": 512
} |
Steel.Effect.SteelT | val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a)
: SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v))
(fun v -> pts_to r p v `star` q v) | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v:a) -> pts_to r p v `star` q v);
exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v))
(fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v);
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop
(H.pts_to r p (hide x) `star` U.lift_dom q x)
(pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ());
return (U.downgrade_val x) | val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a)
: SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v))
(fun v -> pts_to r p v `star` q v)
let read_refine_pt #a #p q r = | true | null | false | Classical.forall_intro_2 reveal_equiv;
lift_exists (fun (v: a) -> (pts_to r p v) `star` (q v));
exists_cong (fun (v: U.raise_t a) -> (pts_to r p (U.downgrade_val v)) `star` (q (U.downgrade_val v))
)
(fun (v: U.raise_t a) -> (H.pts_to r p v) `star` (U.lift_dom q v));
let x = H.read_refine (U.lift_dom q) r in
rewrite_slprop ((H.pts_to r p (hide x)) `star` (U.lift_dom q x))
((pts_to r p (U.downgrade_val x)) `star` (q (U.downgrade_val x)))
(fun _ -> ());
return (U.downgrade_val x) | {
"checked_file": "Steel.Reference.fst.checked",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Reference.fst"
} | [] | [
"Steel.FractionalPermission.perm",
"Steel.Effect.Common.vprop",
"Steel.Reference.ref",
"Steel.Effect.Atomic.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.VStar",
"Steel.Reference.pts_to",
"FStar.Universe.downgrade_val",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.Effect.Common.star",
"Steel.HigherReference.pts_to",
"FStar.Universe.raise_t",
"FStar.Universe.lift_dom",
"Steel.Memory.mem",
"Steel.HigherReference.read_refine",
"Steel.Effect.Atomic.exists_cong",
"Steel.Effect.Atomic.lift_exists",
"FStar.Classical.forall_intro_2",
"Prims.l_iff",
"Steel.Effect.Common.equiv",
"Steel.Memory.equiv",
"Steel.Effect.Common.hp_of",
"Steel.Effect.Common.reveal_equiv"
] | [] | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Reference
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module Mem = Steel.Memory
module H = Steel.HigherReference
module U = FStar.Universe
#set-options "--ide_id_info_off"
let ref a = H.ref (U.raise_t a)
let null #a = H.null #(U.raise_t a)
let is_null #a r = H.is_null #(U.raise_t a) r
let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v)
val raise_val_inj (#a:Type) (x y:a) : Lemma
(requires U.raise_val x == U.raise_val y)
(ensures x == y)
let raise_val_inj x y =
U.downgrade_val_raise_val x;
U.downgrade_val_raise_val y
let pts_to_ref_injective
(#a: Type u#0)
(r: ref a)
(p0 p1:perm)
(v0 v1:a)
(m:mem)
: Lemma
(requires
interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m)
(ensures v0 == v1)
= let v0' = U.raise_val v0 in
let v1' = U.raise_val v1 in
H.pts_to_ref_injective r p0 p1 v0' v1' m;
raise_val_inj v0 v1
let pts_to_not_null (#a:Type u#0)
(x:ref a)
(p:perm)
(v:a)
(m:mem)
: Lemma (requires interp (pts_to_sl x p v) m)
(ensures x =!= null)
= let v = U.raise_val v in
H.pts_to_not_null #(U.raise_t a) x p v m
// let pts_to_not_null' (#a:Type u#0)
// (x:ref a)
// (p:perm)
// (v: erased a)
// (m:mem)
// (m1:mem{disjoint m m1})
// : Lemma (requires interp (pts_to_sl x p v) m)
// (ensures interp (pts_to_sl x p v) (Mem.join m m1))
// = ()
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y : a) (m:mem)
: Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m))
(ensures (x == y))
= H.pts_to_witinv r p;
raise_val_inj x y
in
Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1)
(fun m -> pts_to_ref_injective r p0 p1 v0 v1 m);
rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
let alloc_pt x =
let r = H.alloc (U.raise_val x) in
rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ());
return r
let read_pt #a #p #v r =
let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in
rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ());
let x = H.read r in
let v':a = U.downgrade_val x in
rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ());
return v' | false | false | Steel.Reference.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a)
: SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v))
(fun v -> pts_to r p v `star` q v) | [] | Steel.Reference.read_refine_pt | {
"file_name": "lib/steel/Steel.Reference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | q: (_: a -> Steel.Effect.Common.vprop) -> r: Steel.Reference.ref a -> Steel.Effect.SteelT a | {
"end_col": 28,
"end_line": 118,
"start_col": 2,
"start_line": 109
} |
Subsets and Splits