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 | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let block a = lbytes (block_length a) | let block a = | false | null | false | lbytes (block_length a) | {
"checked_file": "Spec.Agile.Cipher.fsti.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.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"
],
"interface_file": false,
"source_file": "Spec.Agile.Cipher.fsti"
} | [
"total"
] | [
"Spec.Agile.Cipher.cipher_alg",
"Lib.ByteSequence.lbytes",
"Spec.Agile.Cipher.block_length"
] | [] | module Spec.Agile.Cipher
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
/// This module is concerned with defining an agile stream cipher, i.e. a
/// function that given: a key; an iv (nonce); a counter, produces a fresh
/// block. We leave details of key expansion to the ``.fst``, or possibly even
/// to the low-level implementation.
val force_flush_interleaving: unit
/// Definitions
/// -----------
type cipher_alg =
| AES128
| AES256
| CHACHA20
/// The AES spec itself is agile; this is the same nested agility technique used
/// for SHA2 vs. MD.
let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) =
match a with
| AES128 -> Spec.AES.AES128
| AES256 -> Spec.AES.AES256
/// Trying to enforce conventions: lengths for nats (spec); len for machine
/// integers (runtime).
let key_length (a: cipher_alg): size_nat =
match a with
| AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.size_key
let key (a: cipher_alg) =
match a with
| AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.key
let block_length (a:cipher_alg) =
match a with
| AES128 | AES256 -> 16
| CHACHA20 -> 64 | false | true | Spec.Agile.Cipher.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val block : a: Spec.Agile.Cipher.cipher_alg -> Type0 | [] | Spec.Agile.Cipher.block | {
"file_name": "specs/Spec.Agile.Cipher.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.Cipher.cipher_alg -> Type0 | {
"end_col": 37,
"end_line": 49,
"start_col": 14,
"start_line": 49
} |
|
Prims.Tot | val key_length (a: cipher_alg) : size_nat | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_length (a: cipher_alg): size_nat =
match a with
| AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.size_key | val key_length (a: cipher_alg) : size_nat
let key_length (a: cipher_alg) : size_nat = | false | null | false | match a with
| AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.size_key | {
"checked_file": "Spec.Agile.Cipher.fsti.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.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"
],
"interface_file": false,
"source_file": "Spec.Agile.Cipher.fsti"
} | [
"total"
] | [
"Spec.Agile.Cipher.cipher_alg",
"Spec.AES.key_size",
"Spec.Agile.Cipher.aes_alg_of_alg",
"Spec.Chacha20.size_key",
"Lib.IntTypes.size_nat"
] | [] | module Spec.Agile.Cipher
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
/// This module is concerned with defining an agile stream cipher, i.e. a
/// function that given: a key; an iv (nonce); a counter, produces a fresh
/// block. We leave details of key expansion to the ``.fst``, or possibly even
/// to the low-level implementation.
val force_flush_interleaving: unit
/// Definitions
/// -----------
type cipher_alg =
| AES128
| AES256
| CHACHA20
/// The AES spec itself is agile; this is the same nested agility technique used
/// for SHA2 vs. MD.
let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) =
match a with
| AES128 -> Spec.AES.AES128
| AES256 -> Spec.AES.AES256
/// Trying to enforce conventions: lengths for nats (spec); len for machine
/// integers (runtime). | false | true | Spec.Agile.Cipher.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_length (a: cipher_alg) : size_nat | [] | Spec.Agile.Cipher.key_length | {
"file_name": "specs/Spec.Agile.Cipher.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.Cipher.cipher_alg -> Lib.IntTypes.size_nat | {
"end_col": 38,
"end_line": 37,
"start_col": 2,
"start_line": 35
} |
Prims.Tot | val ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat):
b:bytes { length b = len }
=
// JP: useful? be overconservative and always do + 1? would necessitate a
// little bit of reasoning on the implementation side, perhaps better to have
// a tighter bound here
let n_blocks: n:nat { n * block_length a >= len } =
if len % block_length a = 0 then
len / block_length a
else
len / block_length a + 1
in
let (), blocks = generate_blocks
(block_length a)
max_size_t
n_blocks
(fun _ -> unit) // extra cruft; no accumulator here
(fun i _ -> (), ctr_block a k iv i )
()
in
Seq.slice blocks 0 len | val ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len}
let ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len} = | false | null | false | let n_blocks:n: nat{n * block_length a >= len} =
if len % block_length a = 0 then len / block_length a else len / block_length a + 1
in
let (), blocks =
generate_blocks (block_length a)
max_size_t
n_blocks
(fun _ -> unit)
(fun i _ -> (), ctr_block a k iv i)
()
in
Seq.slice blocks 0 len | {
"checked_file": "Spec.Agile.Cipher.fsti.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.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"
],
"interface_file": false,
"source_file": "Spec.Agile.Cipher.fsti"
} | [
"total"
] | [
"Spec.Agile.Cipher.cipher_alg",
"Spec.Agile.Cipher.key",
"Spec.Agile.Cipher.nonce",
"Lib.IntTypes.size_nat",
"Lib.Sequence.seq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"Spec.Agile.Cipher.block_length",
"FStar.Seq.Base.slice",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Pervasives.Native.tuple2",
"Prims.unit",
"Lib.IntTypes.int_t",
"Prims.op_Multiply",
"Lib.Sequence.generate_blocks",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Agile.Cipher.ctr_block",
"Prims.op_Addition",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.bool"
] | [] | module Spec.Agile.Cipher
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
/// This module is concerned with defining an agile stream cipher, i.e. a
/// function that given: a key; an iv (nonce); a counter, produces a fresh
/// block. We leave details of key expansion to the ``.fst``, or possibly even
/// to the low-level implementation.
val force_flush_interleaving: unit
/// Definitions
/// -----------
type cipher_alg =
| AES128
| AES256
| CHACHA20
/// The AES spec itself is agile; this is the same nested agility technique used
/// for SHA2 vs. MD.
let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) =
match a with
| AES128 -> Spec.AES.AES128
| AES256 -> Spec.AES.AES256
/// Trying to enforce conventions: lengths for nats (spec); len for machine
/// integers (runtime).
let key_length (a: cipher_alg): size_nat =
match a with
| AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.size_key
let key (a: cipher_alg) =
match a with
| AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a)
| CHACHA20 -> Spec.Chacha20.key
let block_length (a:cipher_alg) =
match a with
| AES128 | AES256 -> 16
| CHACHA20 -> 64
let block a = lbytes (block_length a)
/// Smaller bound than for AES-GCM; no IV reduction.
let nonce_bound (a: cipher_alg) (n_len: nat): Type0 =
match a with
| AES128 | AES256 -> n_len <= block_length a
| CHACHA20 -> n_len == 12
let nonce a = b:bytes { nonce_bound a (length b) }
let ctr = size_nat
/// The stream cipher
/// -----------------
/// One block of pseudo-random bytes.
val ctr_block (a: cipher_alg) (k: key a) (iv: nonce a) (c: ctr): block a
/// A stream of pseudo-random bytes, starting from counter zero. The length is
/// artificially constrained to be < 2^32.
let ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat): | false | false | Spec.Agile.Cipher.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len} | [] | Spec.Agile.Cipher.ctr_stream | {
"file_name": "specs/Spec.Agile.Cipher.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Agile.Cipher.cipher_alg ->
k: Spec.Agile.Cipher.key a ->
iv: Spec.Agile.Cipher.nonce a ->
len: Lib.IntTypes.size_nat
-> b: Lib.ByteSequence.bytes{Lib.Sequence.length b = len} | {
"end_col": 24,
"end_line": 90,
"start_col": 1,
"start_line": 72
} |
FStar.Tactics.Effect.Tac | val tiff: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tiff () : Tac unit =
apply_lemma (`lem_iff_refl) | val tiff: Prims.unit -> Tac unit
let tiff () : Tac unit = | true | null | false | apply_lemma (`lem_iff_refl) | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = () | false | false | FStar.Tactics.Simplifier.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 tiff: Prims.unit -> Tac unit | [] | FStar.Tactics.Simplifier.tiff | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 31,
"end_line": 35,
"start_col": 4,
"start_line": 35
} |
FStar.Tactics.Effect.Tac | val step: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let step () : Tac unit =
apply_lemma (`lem_iff_trans) | val step: Prims.unit -> Tac unit
let step () : Tac unit = | true | null | false | apply_lemma (`lem_iff_trans) | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl) | false | false | FStar.Tactics.Simplifier.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 step: Prims.unit -> Tac unit | [] | FStar.Tactics.Simplifier.step | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 32,
"end_line": 38,
"start_col": 4,
"start_line": 38
} |
FStar.Tactics.Effect.Tac | val simplify: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let simplify () : Tac unit =
apply_lemma (`equiv);
simplify_point () | val simplify: Prims.unit -> Tac unit
let simplify () : Tac unit = | true | null | false | apply_lemma (`equiv);
simplify_point () | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.Simplifier.simplify_point",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val inhabit : unit -> Tac unit
let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail ""
val simplify_point : unit -> Tac unit
val recurse : unit -> Tac unit
let rec simplify_point () =
recurse ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And p q ->
if is_true p then apply_lemma (`lem_true_and_p)
else if is_true q then apply_lemma (`lem_p_and_true)
else if is_false p then apply_lemma (`lem_false_and_p)
else if is_false q then apply_lemma (`lem_p_and_false)
else tiff ()
| Or p q ->
if is_true p then apply_lemma (`lem_true_or_p)
else if is_true q then apply_lemma (`lem_p_or_true)
else if is_false p then apply_lemma (`lem_false_or_p)
else if is_false q then apply_lemma (`lem_p_or_false)
else tiff ()
| Implies p q ->
if is_true p then apply_lemma (`lem_true_imp_p)
else if is_true q then apply_lemma (`lem_p_imp_true)
else if is_false p then apply_lemma (`lem_false_imp_p)
else tiff ()
| Forall _b _sort p ->
if is_true p then apply_lemma (`lem_fa_true)
else if is_false p then or_else (fun () -> apply_lemma (`lem_fa_false); inhabit ()) tiff
else tiff ()
| Exists _b _sort p ->
if is_false p then apply_lemma (`lem_ex_false)
else if is_true p then or_else (fun () -> apply_lemma (`lem_ex_true); inhabit ()) tiff
else tiff ()
| Not p ->
if is_true p then apply_lemma (`lem_neg_true)
else if is_false p then apply_lemma (`lem_neg_false)
else tiff ()
| Iff p q ->
// After applying the lemma, we might still have more simpl to do,
// so add an intermediate step.
step ();
if is_true p then apply_lemma (`lem_true_iff_p)
else if is_true q then apply_lemma (`lem_p_iff_true)
else if is_false p then apply_lemma (`lem_false_iff_p)
else if is_false q then apply_lemma (`lem_p_iff_false)
else tiff ();
simplify_point ()
| _ -> tiff ()
end
| _ -> fail "simplify_point: failed precondition: goal should be `g <==> ?u`"
and recurse () : Tac unit =
step ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And _ _ ->
seq (fun () -> apply_lemma (`and_cong)) simplify_point
| Or _ _ ->
seq (fun () -> apply_lemma (`or_cong)) simplify_point
| Implies _ _ ->
seq (fun () -> apply_lemma (`imp_cong)) simplify_point
| Forall _ _ _ ->
apply_lemma (`fa_cong);
let _ = intro () in
simplify_point ()
| Exists _ _ _ ->
apply_lemma (`ex_cong);
let _ = intro () in
simplify_point ()
| Not _ ->
apply_lemma (`neg_cong);
simplify_point ()
| Iff _ _ ->
seq (fun () -> apply_lemma (`iff_cong)) simplify_point
| _ -> tiff ()
end
| _ -> fail "recurse: failed precondition: goal should be `g <==> ?u`"
val equiv : #p:Type -> #q:Type -> squash (p <==> q) -> squash q -> Lemma p
let equiv #p #q _ _ = () | false | false | FStar.Tactics.Simplifier.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 simplify: Prims.unit -> Tac unit | [] | FStar.Tactics.Simplifier.simplify | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 21,
"end_line": 309,
"start_col": 4,
"start_line": 308
} |
FStar.Tactics.Effect.Tac | val is_false : term -> Tac bool | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | val is_false : term -> Tac bool
let is_false t = | true | null | false | match term_as_formula' t with
| False_ -> true
| _ ->
match inspect t with
| Tv_App l r ->
(match inspect l with
| Tv_Abs b t ->
(match term_as_formula' t with
| False_ -> true
| _ -> false)
| _ -> false)
| _ -> false | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"FStar.Tactics.NamedView.term",
"Prims.bool",
"FStar.Reflection.V2.Formula.formula",
"FStar.Reflection.V2.Data.argv",
"FStar.Tactics.NamedView.binder",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool | false | false | FStar.Tactics.Simplifier.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_false : term -> Tac bool | [] | FStar.Tactics.Simplifier.is_false | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 14,
"end_line": 190,
"start_col": 10,
"start_line": 177
} |
FStar.Tactics.Effect.Tac | val is_true : term -> Tac bool | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | val is_true : term -> Tac bool
let is_true t = | true | null | false | match term_as_formula' t with
| True_ -> true
| _ ->
match inspect t with
| Tv_App l r ->
(match inspect l with
| Tv_Abs b t ->
(match term_as_formula' t with
| True_ -> true
| _ -> false)
| _ -> false)
| _ -> false | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"FStar.Tactics.NamedView.term",
"Prims.bool",
"FStar.Reflection.V2.Formula.formula",
"FStar.Reflection.V2.Data.argv",
"FStar.Tactics.NamedView.binder",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool | false | false | FStar.Tactics.Simplifier.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_true : term -> Tac bool | [] | FStar.Tactics.Simplifier.is_true | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 14,
"end_line": 172,
"start_col": 10,
"start_line": 159
} |
FStar.Tactics.Effect.Tac | val inhabit : unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail "" | val inhabit : unit -> Tac unit
let inhabit () = | true | null | false | let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid
then exact (`42)
else if qn = bool_lid then exact (`true) else if qn = unit_lid then exact (`()) else fail ""
| _ -> fail "" | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [] | [
"Prims.unit",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"FStar.Reflection.Const.int_lid",
"FStar.Tactics.V2.Derived.exact",
"Prims.bool",
"FStar.Reflection.Const.bool_lid",
"FStar.Reflection.Const.unit_lid",
"FStar.Tactics.V2.Derived.fail",
"FStar.Reflection.Types.name",
"FStar.Reflection.V2.Builtins.inspect_fv",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.inspect",
"FStar.Reflection.Types.typ",
"FStar.Tactics.V2.Derived.cur_goal"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | false | false | FStar.Tactics.Simplifier.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 inhabit : unit -> Tac unit | [] | FStar.Tactics.Simplifier.inhabit | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 18,
"end_line": 203,
"start_col": 16,
"start_line": 194
} |
FStar.Pervasives.Lemma | val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
) | val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f = | false | null | true | FStar.Tactics.Effect.assert_by_tactic ((forall (x: a). p x) <==> (forall (x: a). q x))
(fun _ ->
();
(split ();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (- 1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1])) | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
"lemma"
] | [
"Prims.squash",
"Prims.l_iff",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_Forall",
"Prims.unit",
"FStar.Tactics.V2.Derived.iseq",
"Prims.Cons",
"Prims.Nil",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.pose",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Reflection.Types.term",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Tactics.V2.Derived.nth_var",
"Prims.op_Minus",
"Prims.list",
"FStar.Tactics.V2.Logic.l_intros",
"FStar.Tactics.V2.Logic.split"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) | false | false | FStar.Tactics.Simplifier.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 fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) | [] | FStar.Tactics.Simplifier.fa_cong | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (x: a -> Prims.squash (p x <==> q x))
-> FStar.Pervasives.Lemma (ensures (forall (x: a). p x) <==> (forall (x: a). q x)) | {
"end_col": 3,
"end_line": 132,
"start_col": 2,
"start_line": 122
} |
FStar.Pervasives.Lemma | val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
)) | val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f = | false | null | true | FStar.Tactics.Effect.assert_by_tactic ((exists (x: a). p x) <==> (exists (x: a). q x))
(fun _ ->
();
(assume_safe (fun () ->
split ();
let do1 () : Tac unit =
let [ex] = l_intros () in
let b, pf = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]))) | {
"checked_file": "FStar.Tactics.Simplifier.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
"lemma"
] | [
"Prims.squash",
"Prims.l_iff",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_Exists",
"Prims.unit",
"FStar.Tactics.Effect.assume_safe",
"FStar.Tactics.V2.Derived.iseq",
"Prims.Cons",
"Prims.Nil",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.pose",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Reflection.Types.term",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Logic.elim_exists",
"Prims.list",
"FStar.Tactics.V2.Logic.l_intros",
"FStar.Tactics.V2.Logic.split"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) | false | false | FStar.Tactics.Simplifier.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 ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) | [] | FStar.Tactics.Simplifier.ex_cong | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (x: a -> Prims.squash (p x <==> q x))
-> FStar.Pervasives.Lemma (ensures (exists (x: a). p x) <==> (exists (x: a). q x)) | {
"end_col": 4,
"end_line": 148,
"start_col": 2,
"start_line": 138
} |
Prims.Tot | val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a) | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ex_proj1 #a #p e = (elift1 (exists_proj1 #a #p)) e | val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a)
let ex_proj1 #a #p e = | false | null | false | (elift1 (exists_proj1 #a #p)) e | {
"checked_file": "FStar.ErasedLogic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.ErasedLogic.fst"
} | [
"total"
] | [
"FStar.ErasedLogic.ex",
"FStar.Ghost.elift1",
"Prims.l_Exists",
"FStar.ErasedLogic.exists_proj1",
"FStar.Ghost.erased"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ErasedLogic
(*F* 's exists should be thought of Coq's sigT. It is totally unerased *)
(*Coq has 2 more versions, with increasing degree of erasure*)
(* https://coq.inria.fr/library/Coq.Init.Specif.html#sigT *)
open FStar.Ghost
(*you can get the witness x, that the proof part is erased*)
(*https://coq.inria.fr/library/Coq.Init.Specif.html#sig*)
type sig_ (a:Type) (p: a->Type) = exists (x:a). (erased (p x))
(*you get nothing. Of course, in ghost contexts, or to build other erased date, you get everything*)
(* https://coq.inria.fr/library/Coq.Init.Logic.html#ex *)
type ex (a:Type) (p:a->Type) = erased (exists (x:a). (p x))
(*how to use the above:*)
(*assuming that existentials in F* are constructive. If so, the following 2 assumes must be definable*)
assume val exists_proj1 : #a:Type -> #p:(a->Type) -> (exists x.p x) -> GTot a
assume val mkexists : #a:Type -> #p:(a->Type) -> x:a -> (p x) -> Tot (exists x.p x) | false | false | FStar.ErasedLogic.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 ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a) | [] | FStar.ErasedLogic.ex_proj1 | {
"file_name": "ulib/legacy/FStar.ErasedLogic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | e: FStar.ErasedLogic.ex a p -> FStar.Ghost.erased a | {
"end_col": 54,
"end_line": 40,
"start_col": 23,
"start_line": 40
} |
Prims.GTot | val gex_proj1 : #a:Type -> #p:(a->Type) -> (ex a p) -> GTot a | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gex_proj1 #a #p e = (reveal (ex_proj1 e)) | val gex_proj1 : #a:Type -> #p:(a->Type) -> (ex a p) -> GTot a
let gex_proj1 #a #p e = | false | null | false | (reveal (ex_proj1 e)) | {
"checked_file": "FStar.ErasedLogic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.ErasedLogic.fst"
} | [
"sometrivial"
] | [
"FStar.ErasedLogic.ex",
"FStar.Ghost.reveal",
"FStar.ErasedLogic.ex_proj1"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ErasedLogic
(*F* 's exists should be thought of Coq's sigT. It is totally unerased *)
(*Coq has 2 more versions, with increasing degree of erasure*)
(* https://coq.inria.fr/library/Coq.Init.Specif.html#sigT *)
open FStar.Ghost
(*you can get the witness x, that the proof part is erased*)
(*https://coq.inria.fr/library/Coq.Init.Specif.html#sig*)
type sig_ (a:Type) (p: a->Type) = exists (x:a). (erased (p x))
(*you get nothing. Of course, in ghost contexts, or to build other erased date, you get everything*)
(* https://coq.inria.fr/library/Coq.Init.Logic.html#ex *)
type ex (a:Type) (p:a->Type) = erased (exists (x:a). (p x))
(*how to use the above:*)
(*assuming that existentials in F* are constructive. If so, the following 2 assumes must be definable*)
assume val exists_proj1 : #a:Type -> #p:(a->Type) -> (exists x.p x) -> GTot a
assume val mkexists : #a:Type -> #p:(a->Type) -> x:a -> (p x) -> Tot (exists x.p x)
val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a)
let ex_proj1 #a #p e = (elift1 (exists_proj1 #a #p)) e | false | false | FStar.ErasedLogic.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 gex_proj1 : #a:Type -> #p:(a->Type) -> (ex a p) -> GTot a | [] | FStar.ErasedLogic.gex_proj1 | {
"file_name": "ulib/legacy/FStar.ErasedLogic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | e: FStar.ErasedLogic.ex a p -> Prims.GTot a | {
"end_col": 45,
"end_line": 44,
"start_col": 24,
"start_line": 44
} |
FStar.Pervasives.Lemma | val is_unit: Prims.unit -> Lemma (S.is_unit emp equiv star) | [
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_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_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux | val is_unit: Prims.unit -> Lemma (S.is_unit emp equiv star)
let is_unit () : Lemma (S.is_unit emp equiv star) = | false | null | true | let aux (y: slprop) : Lemma ((star emp y) `equiv` y /\ (star y emp) `equiv` y) =
emp_unit y;
star_commutative emp y
in
Classical.forall_intro aux | {
"checked_file": "Steel.Semantics.Instantiate.fst.checked",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
"lemma"
] | [
"Prims.unit",
"FStar.Classical.forall_intro",
"Steel.Memory.slprop",
"Prims.l_and",
"Steel.Memory.equiv",
"Steel.Memory.star",
"Steel.Memory.emp",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Steel.Memory.star_commutative",
"Steel.Memory.emp_unit",
"Steel.Semantics.Hoare.MST.is_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.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST
let is_unit () | false | false | Steel.Semantics.Instantiate.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_unit: Prims.unit -> Lemma (S.is_unit emp equiv star) | [] | Steel.Semantics.Instantiate.is_unit | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Steel.Semantics.Hoare.MST.is_unit Steel.Memory.emp Steel.Memory.equiv Steel.Memory.star
) | {
"end_col": 30,
"end_line": 27,
"start_col": 3,
"start_line": 23
} |
FStar.Pervasives.Lemma | val state_obeys_st_laws (uses:inames)
: Lemma (S.st_laws (state0 uses)) | [
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let state_obeys_st_laws uses =
Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1:mem)
: Lemma (requires disjoint m0 m1)
(ensures join m0 m1 == join m1 m0)
[SMTPat (disjoint m0 m1)]
= join_commutative m0 m1
in
let aux (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))]
= join_associative m0 m1 m2
in
let aux (p1 p2 p3:slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
[SMTPat ()]
= equiv_extensional_on_star p1 p2 p3
in
() | val state_obeys_st_laws (uses:inames)
: Lemma (S.st_laws (state0 uses))
let state_obeys_st_laws uses = | false | null | true | Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1: mem)
: Lemma (requires disjoint m0 m1) (ensures join m0 m1 == join m1 m0) [SMTPat (disjoint m0 m1)] =
join_commutative m0 m1
in
let aux (m0 m1 m2: mem)
: Lemma (requires disjoint m1 m2 /\ disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))] =
join_associative m0 m1 m2
in
let aux (p1 p2 p3: slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3)) [SMTPat ()] =
equiv_extensional_on_star p1 p2 p3
in
() | {
"checked_file": "Steel.Semantics.Instantiate.fst.checked",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
"lemma"
] | [
"Steel.Memory.inames",
"Steel.Memory.slprop",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Steel.Memory.equiv",
"Steel.Memory.star",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Steel.Memory.equiv_extensional_on_star",
"Steel.Memory.mem",
"Prims.l_and",
"Steel.Memory.disjoint",
"Steel.Memory.join",
"Prims.eq2",
"Prims.prop",
"Steel.Memory.join_associative",
"Steel.Memory.disjoint_join",
"Steel.Memory.join_commutative",
"FStar.Classical.forall_intro_3",
"Steel.Semantics.Instantiate.is_unit",
"FStar.Classical.forall_intro_2",
"Steel.Memory.star_commutative",
"Steel.Memory.star_associative"
] | [] | (*
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.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST
let is_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux
#push-options "--warn_error -271" | false | false | Steel.Semantics.Instantiate.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 state_obeys_st_laws (uses:inames)
: Lemma (S.st_laws (state0 uses)) | [] | Steel.Semantics.Instantiate.state_obeys_st_laws | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | uses: Steel.Memory.inames
-> FStar.Pervasives.Lemma
(ensures Steel.Semantics.Hoare.MST.st_laws (Steel.Semantics.Instantiate.state0 uses)) | {
"end_col": 4,
"end_line": 57,
"start_col": 2,
"start_line": 31
} |
FStar.Pervasives.Lemma | val state_correspondence (inames:inames)
: Lemma
(let s = state_uses inames in
s.S.hprop == slprop /\
s.S.mem == mem /\
s.S.interp == interp /\
s.S.star == star /\
s.S.locks_invariant == locks_invariant inames /\
(forall (p q frame:slprop)
(m0:mem{interp (p `star` frame `star` locks_invariant inames m0) m0})
(m1:mem{interp (q `star` frame `star` locks_invariant inames m1) m1}).
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)) ==>
S.post_preserves_frame #s q frame m0 m1)) | [
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let state_correspondence inames =
let s = state_uses inames in
assert_norm (s.S.hprop == slprop) ;
assert_norm (s.S.mem == mem) ;
assert_norm (s.S.interp == interp);
assert_norm (s.S.star == star);
assert_norm (s.S.locks_invariant == locks_invariant inames) | val state_correspondence (inames:inames)
: Lemma
(let s = state_uses inames in
s.S.hprop == slprop /\
s.S.mem == mem /\
s.S.interp == interp /\
s.S.star == star /\
s.S.locks_invariant == locks_invariant inames /\
(forall (p q frame:slprop)
(m0:mem{interp (p `star` frame `star` locks_invariant inames m0) m0})
(m1:mem{interp (q `star` frame `star` locks_invariant inames m1) m1}).
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)) ==>
S.post_preserves_frame #s q frame m0 m1))
let state_correspondence inames = | false | null | true | let s = state_uses inames in
assert_norm (s.S.hprop == slprop);
assert_norm (s.S.mem == mem);
assert_norm (s.S.interp == interp);
assert_norm (s.S.star == star);
assert_norm (s.S.locks_invariant == locks_invariant inames) | {
"checked_file": "Steel.Semantics.Instantiate.fst.checked",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
"lemma"
] | [
"Steel.Memory.inames",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem",
"Steel.Memory.slprop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant",
"Steel.Memory.locks_invariant",
"Prims.unit",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star",
"Steel.Memory.star",
"Steel.Memory.mem",
"Prims.prop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp",
"Steel.Memory.interp",
"Steel.Semantics.Hoare.MST.st",
"Steel.Semantics.Instantiate.state_uses"
] | [] | (*
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.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST
let is_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux
#push-options "--warn_error -271"
let state_obeys_st_laws uses =
Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1:mem)
: Lemma (requires disjoint m0 m1)
(ensures join m0 m1 == join m1 m0)
[SMTPat (disjoint m0 m1)]
= join_commutative m0 m1
in
let aux (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))]
= join_associative m0 m1 m2
in
let aux (p1 p2 p3:slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
[SMTPat ()]
= equiv_extensional_on_star p1 p2 p3
in
()
#pop-options | false | false | Steel.Semantics.Instantiate.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 state_correspondence (inames:inames)
: Lemma
(let s = state_uses inames in
s.S.hprop == slprop /\
s.S.mem == mem /\
s.S.interp == interp /\
s.S.star == star /\
s.S.locks_invariant == locks_invariant inames /\
(forall (p q frame:slprop)
(m0:mem{interp (p `star` frame `star` locks_invariant inames m0) m0})
(m1:mem{interp (q `star` frame `star` locks_invariant inames m1) m1}).
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)) ==>
S.post_preserves_frame #s q frame m0 m1)) | [] | Steel.Semantics.Instantiate.state_correspondence | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | inames: Steel.Memory.inames
-> FStar.Pervasives.Lemma
(ensures
(let s = Steel.Semantics.Instantiate.state_uses inames in
Mkst0?.hprop s == Steel.Memory.slprop /\ Mkst0?.mem s == Steel.Memory.mem /\
Mkst0?.interp s == Steel.Memory.interp /\ Mkst0?.star s == Steel.Memory.star /\
Mkst0?.locks_invariant s == Steel.Memory.locks_invariant inames /\
(forall (p: Steel.Memory.slprop)
(q: Steel.Memory.slprop)
(frame: Steel.Memory.slprop)
(m0:
Steel.Memory.mem
{ Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star p frame)
(Steel.Memory.locks_invariant inames m0))
m0 })
(m1:
Steel.Memory.mem
{ Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star q frame)
(Steel.Memory.locks_invariant inames m1))
m1 }).
(forall (f_frame: Steel.Memory.mprop frame).
f_frame (Steel.Memory.core_mem m0) == f_frame (Steel.Memory.core_mem m1)) ==>
Steel.Semantics.Hoare.MST.post_preserves_frame q frame m0 m1))) | {
"end_col": 63,
"end_line": 66,
"start_col": 33,
"start_line": 60
} |
Prims.Tot | val is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg | val is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0
let is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 = | false | null | false | length s == nk alg | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.AES.AES_common_s.nk",
"Vale.Def.Prop_s.prop0"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon) | false | true | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 | [] | Vale.AES.AES_BE_s.is_aes_key_word | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | alg: Vale.AES.AES_common_s.algorithm -> s: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> Vale.Def.Prop_s.prop0 | {
"end_col": 78,
"end_line": 29,
"start_col": 60,
"start_line": 29
} |
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def | let eval_rounds_reveal = | false | null | true | opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.eval_rounds",
"Vale.AES.AES_BE_s.eval_rounds_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_rounds_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_rounds == Vale.AES.AES_BE_s.eval_rounds_def) | [] | Vale.AES.AES_BE_s.eval_rounds_reveal | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_rounds == Vale.AES.AES_BE_s.eval_rounds_def) | {
"end_col": 96,
"end_line": 45,
"start_col": 37,
"start_line": 45
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | let eval_round (state round_key: quad32) = | false | null | false | let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.mix_columns",
"Vale.AES.AES_BE_s.shift_rows",
"Vale.AES.AES_common_s.sub_bytes"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s} | false | true | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_round : state: Vale.Def.Types_s.quad32 -> round_key: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | [] | Vale.AES.AES_BE_s.eval_round | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | state: Vale.Def.Types_s.quad32 -> round_key: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | {
"end_col": 3,
"end_line": 37,
"start_col": 41,
"start_line": 32
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_rounds = opaque_make eval_rounds_def | let eval_rounds = | false | null | false | opaque_make eval_rounds_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.eval_rounds_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_rounds : _: Vale.Def.Types_s.quad32 ->
_: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
_: n: Prims.nat{n < FStar.Seq.Base.length _}
-> Vale.Def.Types_s.quad32 | [] | Vale.AES.AES_BE_s.eval_rounds | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
_: Vale.Def.Types_s.quad32 ->
_: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
_: n: Prims.nat{n < FStar.Seq.Base.length _}
-> Vale.Def.Types_s.quad32 | {
"end_col": 64,
"end_line": 44,
"start_col": 37,
"start_line": 44
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def | let eval_cipher_reveal = | false | null | true | opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.l_True",
"Vale.AES.AES_BE_s.eval_cipher",
"Vale.AES.AES_BE_s.eval_cipher_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_cipher_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_cipher == Vale.AES.AES_BE_s.eval_cipher_def) | [] | Vale.AES.AES_BE_s.eval_cipher_reveal | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_cipher == Vale.AES.AES_BE_s.eval_cipher_def) | {
"end_col": 96,
"end_line": 58,
"start_col": 37,
"start_line": 58
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_encrypt_word = opaque_make aes_encrypt_word_def | let aes_encrypt_word = | false | null | false | opaque_make aes_encrypt_word_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True",
"Vale.AES.AES_BE_s.aes_encrypt_word_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
= | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_encrypt_word : alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | [] | Vale.AES.AES_BE_s.aes_encrypt_word | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | {
"end_col": 74,
"end_line": 101,
"start_col": 42,
"start_line": 101
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_cipher = opaque_make eval_cipher_def | let eval_cipher = | false | null | false | opaque_make eval_cipher_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.l_True",
"Vale.AES.AES_BE_s.eval_cipher_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_cipher : alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | [] | Vale.AES.AES_BE_s.eval_cipher | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | {
"end_col": 64,
"end_line": 57,
"start_col": 37,
"start_line": 57
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def | let expand_key_reveal = | false | null | true | opaque_revealer (`%expand_key) expand_key expand_key_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key",
"Vale.AES.AES_BE_s.expand_key_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_key_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.expand_key == Vale.AES.AES_BE_s.expand_key_def) | [] | Vale.AES.AES_BE_s.expand_key_reveal | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.expand_key == Vale.AES.AES_BE_s.expand_key_def) | {
"end_col": 92,
"end_line": 79,
"start_col": 36,
"start_line": 79
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def | let aes_encrypt_word_reveal = | false | null | true | opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.AES.AES_BE_s.aes_encrypt_word_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_encrypt_word_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.aes_encrypt_word == Vale.AES.AES_BE_s.aes_encrypt_word_def) | [] | Vale.AES.AES_BE_s.aes_encrypt_word_reveal | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.aes_encrypt_word == Vale.AES.AES_BE_s.aes_encrypt_word_def) | {
"end_col": 116,
"end_line": 102,
"start_col": 42,
"start_line": 102
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand_key = opaque_make expand_key_def | let expand_key = | false | null | false | opaque_make expand_key_def | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_key : _: Vale.AES.AES_common_s.algorithm ->
_: Vale.AES.AES_BE_s.aes_key_word _ ->
_: size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr _ + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == _} | [] | Vale.AES.AES_BE_s.expand_key | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
_: Vale.AES.AES_common_s.algorithm ->
_: Vale.AES.AES_BE_s.aes_key_word _ ->
_: size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr _ + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == _} | {
"end_col": 62,
"end_line": 78,
"start_col": 36,
"start_line": 78
} |
|
Prims.Pure | val aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key) | val aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True)
let aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) = | false | null | false | eval_cipher_def alg input (key_to_round_keys_word alg key) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.eval_cipher_def",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | [] | Vale.AES.AES_BE_s.aes_encrypt_word_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | {
"end_col": 60,
"end_line": 100,
"start_col": 2,
"start_line": 100
} |
Prims.Pure | val key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1))) | val key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
let key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) = | false | null | false | key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1))) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.AES_BE_s.key_schedule_to_round_keys",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Vale.AES.AES_BE_s.expand_key",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) | [] | Vale.AES.AES_BE_s.key_to_round_keys_word | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> Prims.Pure (FStar.Seq.Base.seq Vale.Def.Types_s.quad32) | {
"end_col": 82,
"end_line": 94,
"start_col": 2,
"start_line": 94
} |
Prims.Tot | val eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys}) : quad32 | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | val eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys}) : quad32
let rec eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys})
: quad32 = | false | null | false | if n = 0 then init else eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Vale.AES.AES_BE_s.eval_round",
"Vale.AES.AES_BE_s.eval_rounds_def",
"Prims.op_Subtraction",
"FStar.Seq.Base.index"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys}) : quad32 | [
"recursion"
] | Vale.AES.AES_BE_s.eval_rounds_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
init: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
n: Prims.nat{n < FStar.Seq.Base.length round_keys}
-> Vale.Def.Types_s.quad32 | {
"end_col": 77,
"end_line": 43,
"start_col": 2,
"start_line": 40
} |
Prims.Tot | val key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk) | val key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds})
let rec key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) = | false | null | false | if rounds = 0
then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk =
Mkfour (index w (4 * rounds - 1))
(index w (4 * rounds - 2))
(index w (4 * rounds - 3))
(index w (4 * rounds - 4))
in
append round_keys (create 1 rk) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Mul.op_Star",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.empty",
"Vale.Def.Types_s.quad32",
"Prims.bool",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.Mkfour",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"Prims.eq2",
"Vale.AES.AES_BE_s.key_schedule_to_round_keys"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds}) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) | [
"recursion"
] | Vale.AES.AES_BE_s.key_schedule_to_round_keys | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
rounds: Prims.nat ->
w: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length w >= 4 * rounds}
-> round_keys:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32 {FStar.Seq.Base.length round_keys == rounds} | {
"end_col": 35,
"end_line": 87,
"start_col": 2,
"start_line": 83
} |
Prims.Tot | val aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aes_encrypt (alg:algorithm) (key:aes_key alg) (input:seq16 nat8) : seq16 nat8 =
let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input) | val aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8
let aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 = | false | null | false | let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_common_s.aes_key",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Types_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.be_bytes_to_quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def
#push-options "--z3rlimit 20"
let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word))
#pop-options | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 | [] | Vale.AES.AES_BE_s.aes_encrypt | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
key: Vale.AES.AES_common_s.aes_key alg ->
input: Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8
-> Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8 | {
"end_col": 58,
"end_line": 114,
"start_col": 83,
"start_line": 111
} |
Prims.Tot | val expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | val expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size})
let rec expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) = | false | null | false | if size = 0
then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg
then append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0
then nat32_xor (sub_word (rot_word (index w (i - 1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then sub_word (index w (i - 1)) else index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.empty",
"Vale.Def.Types_s.nat32",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Vale.AES.AES_common_s.nk",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"Vale.Def.Types_s.nat32_xor",
"Prims.op_Subtraction",
"Vale.Def.Words_s.nat32",
"Prims.op_Modulus",
"Vale.AES.AES_common_s.sub_word",
"Vale.AES.AES_BE_s.rot_word",
"Vale.AES.AES_common_s.aes_rcon",
"Prims.op_Division",
"Prims.op_GreaterThan",
"FStar.Seq.Base.seq",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key_def"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))}) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) | [
"recursion"
] | Vale.AES.AES_BE_s.expand_key_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
key: Vale.AES.AES_BE_s.aes_key_word alg ->
size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr alg + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == size} | {
"end_col": 67,
"end_line": 77,
"start_col": 2,
"start_line": 62
} |
Prims.Tot | val key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word)) | val key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)})
let key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) = | false | null | false | let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word)) | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"total"
] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_common_s.aes_key",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def
#push-options "--z3rlimit 20" | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) | [] | Vale.AES.AES_BE_s.key_to_round_keys | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_common_s.aes_key alg
-> round_keys:
FStar.Seq.Base.seq Vale.Def.Types_s.nat8
{FStar.Seq.Base.length round_keys == 16 * (Vale.AES.AES_common_s.nr alg + 1)} | {
"end_col": 85,
"end_line": 108,
"start_col": 68,
"start_line": 106
} |
Prims.Pure | val eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | val eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True)
let eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) = | false | null | false | let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32_xor",
"FStar.Seq.Base.index",
"Vale.AES.AES_common_s.nr",
"Vale.AES.AES_BE_s.shift_rows",
"Vale.AES.AES_common_s.sub_bytes",
"Vale.AES.AES_BE_s.eval_rounds_def",
"Prims.op_Subtraction",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Prims.l_True"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) | [] | Vale.AES.AES_BE_s.eval_cipher_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | {
"end_col": 7,
"end_line": 56,
"start_col": 3,
"start_line": 50
} |
FStar.Pervasives.Lemma | val lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_shl_rcon (rcon:nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32)
=
Vale.Def.TypesNative_s.reveal_ishl 32 rcon 16;
FStar.UInt.shift_left_value_lemma #32 rcon 16;
Vale.Def.TypesNative_s.reveal_ishl 64 rcon 16;
FStar.UInt.shift_left_value_lemma #64 rcon 16 | val lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32)
let lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) = | false | null | true | Vale.Def.TypesNative_s.reveal_ishl 32 rcon 16;
FStar.UInt.shift_left_value_lemma #32 rcon 16;
Vale.Def.TypesNative_s.reveal_ishl 64 rcon 16;
FStar.UInt.shift_left_value_lemma #64 rcon 16 | {
"checked_file": "Vale.AES.AES_BE_s.fst.checked",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
"lemma"
] | [
"Vale.Def.Types_s.nat8",
"FStar.UInt.shift_left_value_lemma",
"Prims.unit",
"Vale.Def.TypesNative_s.reveal_ishl",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Vale.Arch.Types.ishl32",
"Prims.op_Modulus",
"Vale.Arch.Types.ishl64",
"Vale.Def.Words_s.pow2_32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def
#push-options "--z3rlimit 20"
let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word))
#pop-options
let aes_encrypt (alg:algorithm) (key:aes_key alg) (input:seq16 nat8) : seq16 nat8 =
let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input)
let lemma_shl_rcon (rcon:nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) | false | false | Vale.AES.AES_BE_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) | [] | Vale.AES.AES_BE_s.lemma_shl_rcon | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | rcon: Vale.Def.Types_s.nat8
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.ishl32 rcon 16 == Vale.Arch.Types.ishl64 rcon 16 % Vale.Def.Words_s.pow2_32) | {
"end_col": 47,
"end_line": 121,
"start_col": 2,
"start_line": 118
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.IntegerIntervals",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Equiv",
"short_module": "CE"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": "CF"
},
{
"abbrev": false,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let double_fold #c #eq #a0 (#ak: not_less_than a0) #b0 (#bk:not_less_than b0)
(cm: CE.cm c eq)
(g: ifrom_ito a0 ak -> ifrom_ito b0 bk -> c) =
CF.fold cm a0 ak (fun (i: ifrom_ito a0 ak) -> CF.fold cm b0 bk (g i)) | let double_fold
#c
#eq
#a0
(#ak: not_less_than a0)
#b0
(#bk: not_less_than b0)
(cm: CE.cm c eq)
(g: (ifrom_ito a0 ak -> ifrom_ito b0 bk -> c))
= | false | null | false | CF.fold cm a0 ak (fun (i: ifrom_ito a0 ak) -> CF.fold cm b0 bk (g i)) | {
"checked_file": "FStar.Algebra.CommMonoid.Fold.Nested.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IntegerIntervals.fst.checked",
"FStar.Algebra.CommMonoid.Fold.fsti.checked",
"FStar.Algebra.CommMonoid.Equiv.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Algebra.CommMonoid.Fold.Nested.fsti"
} | [
"total"
] | [
"FStar.Algebra.CommMonoid.Equiv.equiv",
"Prims.int",
"FStar.IntegerIntervals.not_less_than",
"FStar.Algebra.CommMonoid.Equiv.cm",
"FStar.IntegerIntervals.ifrom_ito",
"FStar.Algebra.CommMonoid.Fold.fold"
] | [] | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: A. Rozanov
*)
(*
Here we reason about nested folds of functions over arbitrary
integer intervals. We call such functions generators.
*)
module FStar.Algebra.CommMonoid.Fold.Nested
module CF = FStar.Algebra.CommMonoid.Fold
module CE = FStar.Algebra.CommMonoid.Equiv
open FStar.IntegerIntervals
(* This constructs a generator function that has its arguments in reverse
order. Useful when reasoning about nested folds, transposed matrices, etc.
Note how this utility is more general than transposed_matrix_gen
found in FStar.Seq.Matrix -- but for zero-based domains, latter is
more convenient. *)
let transpose_generator #c (#m0 #mk: int)
(#n0 #nk: int)
(gen: ifrom_ito m0 mk -> ifrom_ito n0 nk -> c)
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c) { forall i j. f j i == gen i j })
= fun j i -> gen i j
let double_fold #c #eq #a0 (#ak: not_less_than a0) #b0 (#bk:not_less_than b0)
(cm: CE.cm c eq) | false | false | FStar.Algebra.CommMonoid.Fold.Nested.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val double_fold : cm: FStar.Algebra.CommMonoid.Equiv.cm c eq ->
g: (_: FStar.IntegerIntervals.ifrom_ito a0 ak -> _: FStar.IntegerIntervals.ifrom_ito b0 bk -> c)
-> c | [] | FStar.Algebra.CommMonoid.Fold.Nested.double_fold | {
"file_name": "ulib/FStar.Algebra.CommMonoid.Fold.Nested.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
cm: FStar.Algebra.CommMonoid.Equiv.cm c eq ->
g: (_: FStar.IntegerIntervals.ifrom_ito a0 ak -> _: FStar.IntegerIntervals.ifrom_ito b0 bk -> c)
-> c | {
"end_col": 71,
"end_line": 46,
"start_col": 2,
"start_line": 46
} |
|
Prims.Tot | val transpose_generator
(#c: _)
(#m0 #mk #n0 #nk: int)
(gen: (ifrom_ito m0 mk -> ifrom_ito n0 nk -> c))
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c){forall i j. f j i == gen i j}) | [
{
"abbrev": false,
"full_module": "FStar.IntegerIntervals",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Equiv",
"short_module": "CE"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": "CF"
},
{
"abbrev": false,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Algebra.CommMonoid.Fold",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let transpose_generator #c (#m0 #mk: int)
(#n0 #nk: int)
(gen: ifrom_ito m0 mk -> ifrom_ito n0 nk -> c)
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c) { forall i j. f j i == gen i j })
= fun j i -> gen i j | val transpose_generator
(#c: _)
(#m0 #mk #n0 #nk: int)
(gen: (ifrom_ito m0 mk -> ifrom_ito n0 nk -> c))
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c){forall i j. f j i == gen i j})
let transpose_generator
#c
(#m0: int)
(#mk: int)
(#n0: int)
(#nk: int)
(gen: (ifrom_ito m0 mk -> ifrom_ito n0 nk -> c))
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c){forall i j. f j i == gen i j}) = | false | null | false | fun j i -> gen i j | {
"checked_file": "FStar.Algebra.CommMonoid.Fold.Nested.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IntegerIntervals.fst.checked",
"FStar.Algebra.CommMonoid.Fold.fsti.checked",
"FStar.Algebra.CommMonoid.Equiv.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Algebra.CommMonoid.Fold.Nested.fsti"
} | [
"total"
] | [
"Prims.int",
"FStar.IntegerIntervals.ifrom_ito",
"Prims.l_Forall",
"Prims.eq2"
] | [] | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: A. Rozanov
*)
(*
Here we reason about nested folds of functions over arbitrary
integer intervals. We call such functions generators.
*)
module FStar.Algebra.CommMonoid.Fold.Nested
module CF = FStar.Algebra.CommMonoid.Fold
module CE = FStar.Algebra.CommMonoid.Equiv
open FStar.IntegerIntervals
(* This constructs a generator function that has its arguments in reverse
order. Useful when reasoning about nested folds, transposed matrices, etc.
Note how this utility is more general than transposed_matrix_gen
found in FStar.Seq.Matrix -- but for zero-based domains, latter is
more convenient. *)
let transpose_generator #c (#m0 #mk: int)
(#n0 #nk: int)
(gen: ifrom_ito m0 mk -> ifrom_ito n0 nk -> c) | false | false | FStar.Algebra.CommMonoid.Fold.Nested.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val transpose_generator
(#c: _)
(#m0 #mk #n0 #nk: int)
(gen: (ifrom_ito m0 mk -> ifrom_ito n0 nk -> c))
: (f: (ifrom_ito n0 nk -> ifrom_ito m0 mk -> c){forall i j. f j i == gen i j}) | [] | FStar.Algebra.CommMonoid.Fold.Nested.transpose_generator | {
"file_name": "ulib/FStar.Algebra.CommMonoid.Fold.Nested.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | gen: (_: FStar.IntegerIntervals.ifrom_ito m0 mk -> _: FStar.IntegerIntervals.ifrom_ito n0 nk -> c)
-> f:
(_: FStar.IntegerIntervals.ifrom_ito n0 nk -> _: FStar.IntegerIntervals.ifrom_ito m0 mk -> c)
{ forall (i: FStar.IntegerIntervals.ifrom_ito m0 mk)
(j: FStar.IntegerIntervals.ifrom_ito n0 nk).
f j i == gen i j } | {
"end_col": 22,
"end_line": 41,
"start_col": 4,
"start_line": 41
} |
Prims.Tot | val va_quick_Loop (in_b k_b: buffer128) : (va_quickCode unit (va_code_Loop ())) | [
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_quick_Loop (in_b:buffer128) (k_b:buffer128) : (va_quickCode unit (va_code_Loop ())) =
(va_QProc (va_code_Loop ()) ([va_Mod_vec 31; va_Mod_vec 30; va_Mod_vec 29; va_Mod_vec 28;
va_Mod_vec 26; va_Mod_vec 25; va_Mod_vec 24; va_Mod_vec 23; va_Mod_vec 22; va_Mod_vec 21;
va_Mod_vec 20; va_Mod_vec 19; va_Mod_vec 18; va_Mod_vec 17; va_Mod_vec 16; va_Mod_vec 15;
va_Mod_vec 14; va_Mod_vec 13; va_Mod_vec 12; va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec
2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_cr0; va_Mod_reg 5; va_Mod_reg 6; va_Mod_reg 4])
(va_wp_Loop in_b k_b) (va_wpProof_Loop in_b k_b)) | val va_quick_Loop (in_b k_b: buffer128) : (va_quickCode unit (va_code_Loop ()))
let va_quick_Loop (in_b k_b: buffer128) : (va_quickCode unit (va_code_Loop ())) = | false | null | false | (va_QProc (va_code_Loop ())
([
va_Mod_vec 31; va_Mod_vec 30; va_Mod_vec 29; va_Mod_vec 28; va_Mod_vec 26; va_Mod_vec 25;
va_Mod_vec 24; va_Mod_vec 23; va_Mod_vec 22; va_Mod_vec 21; va_Mod_vec 20; va_Mod_vec 19;
va_Mod_vec 18; va_Mod_vec 17; va_Mod_vec 16; va_Mod_vec 15; va_Mod_vec 14; va_Mod_vec 13;
va_Mod_vec 12; va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7;
va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1;
va_Mod_vec 0; va_Mod_cr0; va_Mod_reg 5; va_Mod_reg 6; va_Mod_reg 4
])
(va_wp_Loop in_b k_b)
(va_wpProof_Loop in_b k_b)) | {
"checked_file": "Vale.SHA.PPC64LE.Loop.fsti.checked",
"dependencies": [
"Vale.SHA2.Wrapper.fsti.checked",
"Vale.SHA.PPC64LE.SHA_helpers.fsti.checked",
"Vale.SHA.PPC64LE.Rounds.fsti.checked",
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.Stack_i.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsStack.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Spec.SHA2.fsti.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.SHA.PPC64LE.Loop.fsti"
} | [
"total"
] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.SHA.PPC64LE.Loop.va_code_Loop",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_cr0",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.SHA.PPC64LE.Loop.va_wp_Loop",
"Vale.SHA.PPC64LE.Loop.va_wpProof_Loop",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | module Vale.SHA.PPC64LE.Loop
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.Stack_i
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsStack
open Vale.PPC64LE.InsVector
open Vale.SHA.PPC64LE.SHA_helpers
open Spec.SHA2
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Loops
open Vale.SHA.PPC64LE.Rounds
open Vale.SHA2.Wrapper
#reset-options "--z3rlimit 2000"
//-- Loop
val va_code_Loop : va_dummy:unit -> Tot va_code
val va_codegen_success_Loop : va_dummy:unit -> Tot va_pbool
val va_lemma_Loop : va_b0:va_code -> va_s0:va_state -> in_b:buffer128 -> k_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop ()) va_s0 /\ va_get_ok va_s0 /\
(Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) in_b (4
`op_Multiply` va_get_reg 5 va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 16
(va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validSrcAddrsOffset128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 13 3 (va_get_mem_layout va_s0) Secret /\
va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 < pow2_64 /\ va_get_reg 6 va_s0 + 256
< pow2_64 /\ Vale.SHA.PPC64LE.SHA_helpers.k_reqs (Vale.PPC64LE.Decls.buffer128_as_seq
(va_get_mem_heaplet 0 va_s0) k_b))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(va_get_reg 4 va_sM == va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 /\ va_get_reg 5
va_sM == 0 /\ (let input_LE = FStar.Seq.Base.slice #Vale.PPC64LE.Machine_s.quad32
(Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) in_b) 0 (4 `op_Multiply`
va_get_reg 5 va_s0) in let input_BE = Vale.Arch.Types.reverse_bytes_quad32_seq input_LE in
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_sM) (va_get_vec 17
va_sM) (va_get_vec 18 va_sM) (va_get_vec 19 va_sM) (va_get_vec 20 va_sM) (va_get_vec 21 va_sM)
(va_get_vec 22 va_sM) (va_get_vec 23 va_sM) == Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads
input_BE (Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_s0)
(va_get_vec 17 va_s0) (va_get_vec 18 va_s0) (va_get_vec 19 va_s0) (va_get_vec 20 va_s0)
(va_get_vec 21 va_s0) (va_get_vec 22 va_s0) (va_get_vec 23 va_s0)))) /\ va_state_eq va_sM
(va_update_vec 31 va_sM (va_update_vec 30 va_sM (va_update_vec 29 va_sM (va_update_vec 28 va_sM
(va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_vec 24 va_sM (va_update_vec 23 va_sM
(va_update_vec 22 va_sM (va_update_vec 21 va_sM (va_update_vec 20 va_sM (va_update_vec 19 va_sM
(va_update_vec 18 va_sM (va_update_vec 17 va_sM (va_update_vec 16 va_sM (va_update_vec 15 va_sM
(va_update_vec 14 va_sM (va_update_vec 13 va_sM (va_update_vec 12 va_sM (va_update_vec 11 va_sM
(va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 7 va_sM
(va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_cr0 va_sM
(va_update_reg 5 va_sM (va_update_reg 6 va_sM (va_update_reg 4 va_sM (va_update_ok va_sM
va_s0))))))))))))))))))))))))))))))))))))))
[@ va_qattr]
let va_wp_Loop (in_b:buffer128) (k_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0))
: Type0 =
(va_get_ok va_s0 /\ (Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg
4 va_s0) in_b (4 `op_Multiply` va_get_reg 5 va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 16
(va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validSrcAddrsOffset128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 13 3 (va_get_mem_layout va_s0) Secret /\
va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 < pow2_64 /\ va_get_reg 6 va_s0 + 256
< pow2_64 /\ Vale.SHA.PPC64LE.SHA_helpers.k_reqs (Vale.PPC64LE.Decls.buffer128_as_seq
(va_get_mem_heaplet 0 va_s0) k_b)) /\ (forall (va_x_r4:nat64) (va_x_r6:nat64) (va_x_r5:nat64)
(va_x_cr0:cr0_t) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) (va_x_v11:quad32) (va_x_v12:quad32) (va_x_v13:quad32)
(va_x_v14:quad32) (va_x_v15:quad32) (va_x_v16:quad32) (va_x_v17:quad32) (va_x_v18:quad32)
(va_x_v19:quad32) (va_x_v20:quad32) (va_x_v21:quad32) (va_x_v22:quad32) (va_x_v23:quad32)
(va_x_v24:quad32) (va_x_v25:quad32) (va_x_v26:quad32) (va_x_v28:quad32) (va_x_v29:quad32)
(va_x_v30:quad32) (va_x_v31:quad32) . let va_sM = va_upd_vec 31 va_x_v31 (va_upd_vec 30
va_x_v30 (va_upd_vec 29 va_x_v29 (va_upd_vec 28 va_x_v28 (va_upd_vec 26 va_x_v26 (va_upd_vec 25
va_x_v25 (va_upd_vec 24 va_x_v24 (va_upd_vec 23 va_x_v23 (va_upd_vec 22 va_x_v22 (va_upd_vec 21
va_x_v21 (va_upd_vec 20 va_x_v20 (va_upd_vec 19 va_x_v19 (va_upd_vec 18 va_x_v18 (va_upd_vec 17
va_x_v17 (va_upd_vec 16 va_x_v16 (va_upd_vec 15 va_x_v15 (va_upd_vec 14 va_x_v14 (va_upd_vec 13
va_x_v13 (va_upd_vec 12 va_x_v12 (va_upd_vec 11 va_x_v11 (va_upd_vec 10 va_x_v10 (va_upd_vec 9
va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_cr0 va_x_cr0 (va_upd_reg 5 va_x_r5 (va_upd_reg 6 va_x_r6
(va_upd_reg 4 va_x_r4 va_s0)))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ (va_get_reg
4 va_sM == va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 /\ va_get_reg 5 va_sM == 0
/\ (let input_LE = FStar.Seq.Base.slice #Vale.PPC64LE.Machine_s.quad32
(Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) in_b) 0 (4 `op_Multiply`
va_get_reg 5 va_s0) in let input_BE = Vale.Arch.Types.reverse_bytes_quad32_seq input_LE in
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_sM) (va_get_vec 17
va_sM) (va_get_vec 18 va_sM) (va_get_vec 19 va_sM) (va_get_vec 20 va_sM) (va_get_vec 21 va_sM)
(va_get_vec 22 va_sM) (va_get_vec 23 va_sM) == Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads
input_BE (Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_s0)
(va_get_vec 17 va_s0) (va_get_vec 18 va_s0) (va_get_vec 19 va_s0) (va_get_vec 20 va_s0)
(va_get_vec 21 va_s0) (va_get_vec 22 va_s0) (va_get_vec 23 va_s0)))) ==> va_k va_sM (())))
val va_wpProof_Loop : in_b:buffer128 -> k_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Loop in_b k_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop ()) ([va_Mod_vec 31; va_Mod_vec
30; va_Mod_vec 29; va_Mod_vec 28; va_Mod_vec 26; va_Mod_vec 25; va_Mod_vec 24; va_Mod_vec 23;
va_Mod_vec 22; va_Mod_vec 21; va_Mod_vec 20; va_Mod_vec 19; va_Mod_vec 18; va_Mod_vec 17;
va_Mod_vec 16; va_Mod_vec 15; va_Mod_vec 14; va_Mod_vec 13; va_Mod_vec 12; va_Mod_vec 11;
va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec
4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_cr0; va_Mod_reg 5; va_Mod_reg
6; va_Mod_reg 4]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr] | false | false | Vale.SHA.PPC64LE.Loop.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 2000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_quick_Loop (in_b k_b: buffer128) : (va_quickCode unit (va_code_Loop ())) | [] | Vale.SHA.PPC64LE.Loop.va_quick_Loop | {
"file_name": "obj/Vale.SHA.PPC64LE.Loop.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | in_b: Vale.PPC64LE.Memory.buffer128 -> k_b: Vale.PPC64LE.Memory.buffer128
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.SHA.PPC64LE.Loop.va_code_Loop ()) | {
"end_col": 53,
"end_line": 123,
"start_col": 2,
"start_line": 117
} |
Prims.Tot | val va_wp_Loop (in_b k_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 | [
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_wp_Loop (in_b:buffer128) (k_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0))
: Type0 =
(va_get_ok va_s0 /\ (Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg
4 va_s0) in_b (4 `op_Multiply` va_get_reg 5 va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 16
(va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validSrcAddrsOffset128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 13 3 (va_get_mem_layout va_s0) Secret /\
va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 < pow2_64 /\ va_get_reg 6 va_s0 + 256
< pow2_64 /\ Vale.SHA.PPC64LE.SHA_helpers.k_reqs (Vale.PPC64LE.Decls.buffer128_as_seq
(va_get_mem_heaplet 0 va_s0) k_b)) /\ (forall (va_x_r4:nat64) (va_x_r6:nat64) (va_x_r5:nat64)
(va_x_cr0:cr0_t) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) (va_x_v11:quad32) (va_x_v12:quad32) (va_x_v13:quad32)
(va_x_v14:quad32) (va_x_v15:quad32) (va_x_v16:quad32) (va_x_v17:quad32) (va_x_v18:quad32)
(va_x_v19:quad32) (va_x_v20:quad32) (va_x_v21:quad32) (va_x_v22:quad32) (va_x_v23:quad32)
(va_x_v24:quad32) (va_x_v25:quad32) (va_x_v26:quad32) (va_x_v28:quad32) (va_x_v29:quad32)
(va_x_v30:quad32) (va_x_v31:quad32) . let va_sM = va_upd_vec 31 va_x_v31 (va_upd_vec 30
va_x_v30 (va_upd_vec 29 va_x_v29 (va_upd_vec 28 va_x_v28 (va_upd_vec 26 va_x_v26 (va_upd_vec 25
va_x_v25 (va_upd_vec 24 va_x_v24 (va_upd_vec 23 va_x_v23 (va_upd_vec 22 va_x_v22 (va_upd_vec 21
va_x_v21 (va_upd_vec 20 va_x_v20 (va_upd_vec 19 va_x_v19 (va_upd_vec 18 va_x_v18 (va_upd_vec 17
va_x_v17 (va_upd_vec 16 va_x_v16 (va_upd_vec 15 va_x_v15 (va_upd_vec 14 va_x_v14 (va_upd_vec 13
va_x_v13 (va_upd_vec 12 va_x_v12 (va_upd_vec 11 va_x_v11 (va_upd_vec 10 va_x_v10 (va_upd_vec 9
va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_cr0 va_x_cr0 (va_upd_reg 5 va_x_r5 (va_upd_reg 6 va_x_r6
(va_upd_reg 4 va_x_r4 va_s0)))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ (va_get_reg
4 va_sM == va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 /\ va_get_reg 5 va_sM == 0
/\ (let input_LE = FStar.Seq.Base.slice #Vale.PPC64LE.Machine_s.quad32
(Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) in_b) 0 (4 `op_Multiply`
va_get_reg 5 va_s0) in let input_BE = Vale.Arch.Types.reverse_bytes_quad32_seq input_LE in
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_sM) (va_get_vec 17
va_sM) (va_get_vec 18 va_sM) (va_get_vec 19 va_sM) (va_get_vec 20 va_sM) (va_get_vec 21 va_sM)
(va_get_vec 22 va_sM) (va_get_vec 23 va_sM) == Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads
input_BE (Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_s0)
(va_get_vec 17 va_s0) (va_get_vec 18 va_s0) (va_get_vec 19 va_s0) (va_get_vec 20 va_s0)
(va_get_vec 21 va_s0) (va_get_vec 22 va_s0) (va_get_vec 23 va_s0)))) ==> va_k va_sM (()))) | val va_wp_Loop (in_b k_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_Loop (in_b k_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 = | false | null | false | (va_get_ok va_s0 /\
(Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 4 va_s0)
in_b
(4 `op_Multiply` (va_get_reg 5 va_s0))
(va_get_mem_layout va_s0)
Secret /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 6 va_s0)
k_b
16
(va_get_mem_layout va_s0)
Secret /\
Vale.PPC64LE.Decls.validSrcAddrsOffset128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 6 va_s0)
k_b
13
3
(va_get_mem_layout va_s0)
Secret /\ va_get_reg 4 va_s0 + 64 `op_Multiply` (va_get_reg 5 va_s0) < pow2_64 /\
va_get_reg 6 va_s0 + 256 < pow2_64 /\
Vale.SHA.PPC64LE.SHA_helpers.k_reqs (Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0
va_s0)
k_b)) /\
(forall (va_x_r4: nat64) (va_x_r6: nat64) (va_x_r5: nat64) (va_x_cr0: cr0_t) (va_x_v0: quad32)
(va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32) (va_x_v5: quad32)
(va_x_v6: quad32) (va_x_v7: quad32) (va_x_v8: quad32) (va_x_v9: quad32) (va_x_v10: quad32)
(va_x_v11: quad32) (va_x_v12: quad32) (va_x_v13: quad32) (va_x_v14: quad32) (va_x_v15: quad32)
(va_x_v16: quad32) (va_x_v17: quad32) (va_x_v18: quad32) (va_x_v19: quad32) (va_x_v20: quad32)
(va_x_v21: quad32) (va_x_v22: quad32) (va_x_v23: quad32) (va_x_v24: quad32) (va_x_v25: quad32)
(va_x_v26: quad32) (va_x_v28: quad32) (va_x_v29: quad32) (va_x_v30: quad32) (va_x_v31: quad32)
.
let va_sM =
va_upd_vec 31
va_x_v31
(va_upd_vec 30
va_x_v30
(va_upd_vec 29
va_x_v29
(va_upd_vec 28
va_x_v28
(va_upd_vec 26
va_x_v26
(va_upd_vec 25
va_x_v25
(va_upd_vec 24
va_x_v24
(va_upd_vec 23
va_x_v23
(va_upd_vec 22
va_x_v22
(va_upd_vec 21
va_x_v21
(va_upd_vec 20
va_x_v20
(va_upd_vec 19
va_x_v19
(va_upd_vec 18
va_x_v18
(va_upd_vec 17
va_x_v17
(va_upd_vec 16
va_x_v16
(va_upd_vec 15
va_x_v15
(va_upd_vec 14
va_x_v14
(va_upd_vec 13
va_x_v13
(va_upd_vec 12
va_x_v12
(va_upd_vec 11
va_x_v11
(va_upd_vec 10
va_x_v10
(va_upd_vec
9
va_x_v9
(va_upd_vec
8
va_x_v8
(va_upd_vec
7
va_x_v7
(
va_upd_vec
6
va_x_v6
(
va_upd_vec
5
va_x_v5
(
va_upd_vec
4
va_x_v4
(
va_upd_vec
3
va_x_v3
(
va_upd_vec
2
va_x_v2
(
va_upd_vec
1
va_x_v1
(
va_upd_vec
0
va_x_v0
(
va_upd_cr0
va_x_cr0
(
va_upd_reg
5
va_x_r5
(
va_upd_reg
6
va_x_r6
(
va_upd_reg
4
va_x_r4
va_s0
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))
)))))))))))
in
va_get_ok va_sM /\
(va_get_reg 4 va_sM == va_get_reg 4 va_s0 + 64 `op_Multiply` (va_get_reg 5 va_s0) /\
va_get_reg 5 va_sM == 0 /\
(let input_LE =
FStar.Seq.Base.slice #Vale.PPC64LE.Machine_s.quad32
(Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) in_b)
0
(4 `op_Multiply` (va_get_reg 5 va_s0))
in
let input_BE = Vale.Arch.Types.reverse_bytes_quad32_seq input_LE in
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_sM)
(va_get_vec 17 va_sM)
(va_get_vec 18 va_sM)
(va_get_vec 19 va_sM)
(va_get_vec 20 va_sM)
(va_get_vec 21 va_sM)
(va_get_vec 22 va_sM)
(va_get_vec 23 va_sM) ==
Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads input_BE
(Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_s0)
(va_get_vec 17 va_s0)
(va_get_vec 18 va_s0)
(va_get_vec 19 va_s0)
(va_get_vec 20 va_s0)
(va_get_vec 21 va_s0)
(va_get_vec 22 va_s0)
(va_get_vec 23 va_s0)))) ==>
va_k va_sM (()))) | {
"checked_file": "Vale.SHA.PPC64LE.Loop.fsti.checked",
"dependencies": [
"Vale.SHA2.Wrapper.fsti.checked",
"Vale.SHA.PPC64LE.SHA_helpers.fsti.checked",
"Vale.SHA.PPC64LE.Rounds.fsti.checked",
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.Stack_i.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsStack.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Spec.SHA2.fsti.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.SHA.PPC64LE.Loop.fsti"
} | [
"total"
] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.va_get_reg",
"Prims.op_Multiply",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.PPC64LE.Decls.validSrcAddrsOffset128",
"Prims.op_LessThan",
"Prims.op_Addition",
"Vale.PPC64LE.Machine_s.pow2_64",
"Vale.SHA.PPC64LE.SHA_helpers.k_reqs",
"Vale.PPC64LE.Decls.buffer128_as_seq",
"Prims.l_Forall",
"Vale.PPC64LE.Memory.nat64",
"Vale.PPC64LE.Machine_s.cr0_t",
"Vale.PPC64LE.Memory.quad32",
"Prims.l_imp",
"Prims.eq2",
"Prims.int",
"Vale.SHA.PPC64LE.SHA_helpers.hash256",
"Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.Arch.Types.reverse_bytes_quad32_seq",
"FStar.Seq.Base.slice",
"Vale.PPC64LE.Machine_s.quad32",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_cr0",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | module Vale.SHA.PPC64LE.Loop
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.Stack_i
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsStack
open Vale.PPC64LE.InsVector
open Vale.SHA.PPC64LE.SHA_helpers
open Spec.SHA2
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Loops
open Vale.SHA.PPC64LE.Rounds
open Vale.SHA2.Wrapper
#reset-options "--z3rlimit 2000"
//-- Loop
val va_code_Loop : va_dummy:unit -> Tot va_code
val va_codegen_success_Loop : va_dummy:unit -> Tot va_pbool
val va_lemma_Loop : va_b0:va_code -> va_s0:va_state -> in_b:buffer128 -> k_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop ()) va_s0 /\ va_get_ok va_s0 /\
(Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) in_b (4
`op_Multiply` va_get_reg 5 va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 16
(va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.validSrcAddrsOffset128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 6 va_s0) k_b 13 3 (va_get_mem_layout va_s0) Secret /\
va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 < pow2_64 /\ va_get_reg 6 va_s0 + 256
< pow2_64 /\ Vale.SHA.PPC64LE.SHA_helpers.k_reqs (Vale.PPC64LE.Decls.buffer128_as_seq
(va_get_mem_heaplet 0 va_s0) k_b))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(va_get_reg 4 va_sM == va_get_reg 4 va_s0 + 64 `op_Multiply` va_get_reg 5 va_s0 /\ va_get_reg 5
va_sM == 0 /\ (let input_LE = FStar.Seq.Base.slice #Vale.PPC64LE.Machine_s.quad32
(Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) in_b) 0 (4 `op_Multiply`
va_get_reg 5 va_s0) in let input_BE = Vale.Arch.Types.reverse_bytes_quad32_seq input_LE in
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_sM) (va_get_vec 17
va_sM) (va_get_vec 18 va_sM) (va_get_vec 19 va_sM) (va_get_vec 20 va_sM) (va_get_vec 21 va_sM)
(va_get_vec 22 va_sM) (va_get_vec 23 va_sM) == Vale.SHA.PPC64LE.SHA_helpers.update_multi_quads
input_BE (Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_get_vec 16 va_s0)
(va_get_vec 17 va_s0) (va_get_vec 18 va_s0) (va_get_vec 19 va_s0) (va_get_vec 20 va_s0)
(va_get_vec 21 va_s0) (va_get_vec 22 va_s0) (va_get_vec 23 va_s0)))) /\ va_state_eq va_sM
(va_update_vec 31 va_sM (va_update_vec 30 va_sM (va_update_vec 29 va_sM (va_update_vec 28 va_sM
(va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_vec 24 va_sM (va_update_vec 23 va_sM
(va_update_vec 22 va_sM (va_update_vec 21 va_sM (va_update_vec 20 va_sM (va_update_vec 19 va_sM
(va_update_vec 18 va_sM (va_update_vec 17 va_sM (va_update_vec 16 va_sM (va_update_vec 15 va_sM
(va_update_vec 14 va_sM (va_update_vec 13 va_sM (va_update_vec 12 va_sM (va_update_vec 11 va_sM
(va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 7 va_sM
(va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_cr0 va_sM
(va_update_reg 5 va_sM (va_update_reg 6 va_sM (va_update_reg 4 va_sM (va_update_ok va_sM
va_s0))))))))))))))))))))))))))))))))))))))
[@ va_qattr]
let va_wp_Loop (in_b:buffer128) (k_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) | false | true | Vale.SHA.PPC64LE.Loop.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 2000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_wp_Loop (in_b k_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 | [] | Vale.SHA.PPC64LE.Loop.va_wp_Loop | {
"file_name": "obj/Vale.SHA.PPC64LE.Loop.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
in_b: Vale.PPC64LE.Memory.buffer128 ->
k_b: Vale.PPC64LE.Memory.buffer128 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | {
"end_col": 94,
"end_line": 102,
"start_col": 2,
"start_line": 69
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_eq = FStar.Tactics.term_eq_old | let term_eq = | true | null | false | FStar.Tactics.term_eq_old | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.Tactics.V1.Builtins.term_eq_old"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions | false | false | FStar.InteractiveHelpers.Effectful.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_eq : _: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.bool | [] | FStar.InteractiveHelpers.Effectful.term_eq | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 39,
"end_line": 12,
"start_col": 14,
"start_line": 12
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_eterm_info = Mketerm_info | let mk_eterm_info = | false | null | false | Mketerm_info | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.Effectful.Mketerm_info"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]" | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_eterm_info : einfo: FStar.InteractiveHelpers.Effectful.effect_info ->
head: FStar.Reflection.Types.term ->
parameters: Prims.list FStar.InteractiveHelpers.Effectful.cast_info
-> FStar.InteractiveHelpers.Effectful.eterm_info | [] | FStar.InteractiveHelpers.Effectful.mk_eterm_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
einfo: FStar.InteractiveHelpers.Effectful.effect_info ->
head: FStar.Reflection.Types.term ->
parameters: Prims.list FStar.InteractiveHelpers.Effectful.cast_info
-> FStar.InteractiveHelpers.Effectful.eterm_info | {
"end_col": 32,
"end_line": 73,
"start_col": 20,
"start_line": 73
} |
|
FStar.Tactics.Effect.Tac | val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv | val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c = | true | null | false | let cv:comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.comp",
"FStar.InteractiveHelpers.Effectful.comp_view_to_effect_info",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.Reflection.V1.Data.comp_view",
"FStar.Reflection.V1.Builtins.inspect_comp"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info) | [] | FStar.InteractiveHelpers.Effectful.comp_to_effect_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> c: FStar.Reflection.Types.comp
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option FStar.InteractiveHelpers.Effectful.effect_info) | {
"end_col": 33,
"end_line": 148,
"start_col": 31,
"start_line": 146
} |
Prims.Tot | val has_refinement (ty: type_info) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin | val has_refinement (ty: type_info) : Tot bool
let has_refinement (ty: type_info) : Tot bool = | false | null | false | Some? ty.refin | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__refin",
"Prims.bool"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *) | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val has_refinement (ty: type_info) : Tot bool | [] | FStar.InteractiveHelpers.Effectful.has_refinement | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.InteractiveHelpers.ExploreTerm.type_info -> Prims.bool | {
"end_col": 16,
"end_line": 227,
"start_col": 2,
"start_line": 227
} |
Prims.Tot | val get_rawest_type (ty: type_info) : Tot typ | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_rawest_type (ty:type_info) : Tot typ =
ty.ty | val get_rawest_type (ty: type_info) : Tot typ
let get_rawest_type (ty: type_info) : Tot typ = | false | null | false | ty.ty | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__ty",
"FStar.Reflection.Types.typ"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_rawest_type (ty: type_info) : Tot typ | [] | FStar.InteractiveHelpers.Effectful.get_rawest_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.InteractiveHelpers.ExploreTerm.type_info -> FStar.Reflection.Types.typ | {
"end_col": 7,
"end_line": 236,
"start_col": 2,
"start_line": 236
} |
FStar.Tactics.Effect.Tac | val cast_info_to_string : cast_info -> Tac string | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")" | val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info = | true | null | false | "Mkcast_info (" ^
term_to_string info.term ^
") (" ^
option_to_string type_info_to_string info.p_ty ^
") (" ^ option_to_string type_info_to_string info.exp_ty ^ ")" | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Effectful.cast_info",
"Prims.op_Hat",
"Prims.string",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.type_info_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__exp_ty",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__p_ty",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__term"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cast_info_to_string : cast_info -> Tac string | [] | FStar.InteractiveHelpers.Effectful.cast_info_to_string | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | info: FStar.InteractiveHelpers.Effectful.cast_info -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 56,
"end_line": 35,
"start_col": 2,
"start_line": 33
} |
FStar.Tactics.Effect.Tac | val eterm_info_to_string : eterm_info -> Tac string | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]" | val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info = | true | null | false | let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^ term_to_string info.head ^ ")\n[" ^ params_str ^ "]" | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Effectful.eterm_info",
"Prims.op_Hat",
"Prims.string",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mketerm_info__item__head",
"FStar.InteractiveHelpers.Effectful.effect_info_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mketerm_info__item__einfo",
"FStar.List.Tot.Base.fold_left",
"Prims.list",
"FStar.Tactics.Util.map",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.InteractiveHelpers.Effectful.cast_info_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mketerm_info__item__parameters"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
} | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eterm_info_to_string : eterm_info -> Tac string | [] | FStar.InteractiveHelpers.Effectful.eterm_info_to_string | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | info: FStar.InteractiveHelpers.Effectful.eterm_info -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 18,
"end_line": 71,
"start_col": 31,
"start_line": 65
} |
FStar.Tactics.Effect.Tac | val effect_info_to_string : effect_info -> Tac string | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")" | val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c = | true | null | false | "Mkeffect_info " ^
effect_type_to_string c.ei_type ^
" (" ^
option_to_string term_to_string c.ei_pre ^
") (" ^ type_info_to_string c.ei_ret_type ^ ") (" ^ option_to_string term_to_string c.ei_post ^ ")" | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Effectful.effect_info",
"Prims.op_Hat",
"Prims.string",
"FStar.InteractiveHelpers.ExploreTerm.effect_type_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_type",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_post",
"FStar.InteractiveHelpers.ExploreTerm.type_info_to_string",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_ret_type",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_pre"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val effect_info_to_string : effect_info -> Tac string | [] | FStar.InteractiveHelpers.Effectful.effect_info_to_string | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | c: FStar.InteractiveHelpers.Effectful.effect_info -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 49,
"end_line": 54,
"start_col": 2,
"start_line": 50
} |
FStar.Tactics.Effect.Tac | val opt_remove_refin : typ -> Tac typ | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty | val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty = | true | null | false | match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.Reflection.Types.typ",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val opt_remove_refin : typ -> Tac typ | [] | FStar.InteractiveHelpers.Effectful.opt_remove_refin | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.typ | {
"end_col": 11,
"end_line": 391,
"start_col": 2,
"start_line": 389
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_effect_info = Mkeffect_info | let mk_effect_info = | false | null | false | Mkeffect_info | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.Effectful.Mkeffect_info"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
} | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_effect_info : ei_type: FStar.InteractiveHelpers.ExploreTerm.effect_type ->
ei_ret_type: FStar.InteractiveHelpers.ExploreTerm.type_info ->
ei_pre: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
ei_post: FStar.Pervasives.Native.option FStar.Reflection.Types.term
-> FStar.InteractiveHelpers.Effectful.effect_info | [] | FStar.InteractiveHelpers.Effectful.mk_effect_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
ei_type: FStar.InteractiveHelpers.ExploreTerm.effect_type ->
ei_ret_type: FStar.InteractiveHelpers.ExploreTerm.type_info ->
ei_pre: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
ei_post: FStar.Pervasives.Native.option FStar.Reflection.Types.term
-> FStar.InteractiveHelpers.Effectful.effect_info | {
"end_col": 34,
"end_line": 45,
"start_col": 21,
"start_line": 45
} |
|
Prims.Tot | val get_opt_refinment (ty: type_info) : Tot (option term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin | val get_opt_refinment (ty: type_info) : Tot (option term)
let get_opt_refinment (ty: type_info) : Tot (option term) = | false | null | false | ty.refin | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__refin",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.term"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_opt_refinment (ty: type_info) : Tot (option term) | [] | FStar.InteractiveHelpers.Effectful.get_opt_refinment | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.InteractiveHelpers.ExploreTerm.type_info
-> FStar.Pervasives.Native.option FStar.Reflection.Types.term | {
"end_col": 10,
"end_line": 233,
"start_col": 2,
"start_line": 233
} |
FStar.Tactics.Effect.Tac | val tcc_no_lift : env -> term -> Tac comp | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t | val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t = | true | null | false | match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ -> tcc e t | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Data.argv",
"Prims.list",
"FStar.InteractiveHelpers.ExploreTerm.inst_comp",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.Types.comp",
"FStar.Tactics.V1.Builtins.tcc",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_app",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tcc_no_lift : env -> term -> Tac comp | [] | FStar.InteractiveHelpers.Effectful.tcc_no_lift | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | e: FStar.Reflection.Types.env -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.comp | {
"end_col": 11,
"end_line": 199,
"start_col": 2,
"start_line": 192
} |
FStar.Tactics.Effect.Tac | val mk_has_type : term -> typ -> Tac term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params | val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty = | true | null | false | let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Derived.mk_app",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.Q_Implicit",
"FStar.Reflection.V1.Data.Q_Explicit",
"Prims.Nil"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty] | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_has_type : term -> typ -> Tac term | [] | FStar.InteractiveHelpers.Effectful.mk_has_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> ty: FStar.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term | {
"end_col": 27,
"end_line": 304,
"start_col": 22,
"start_line": 302
} |
FStar.Tactics.Effect.Tac | val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl | val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls = | true | null | false | let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.List.Tot.Base.flatten",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.Tactics.Util.map",
"FStar.InteractiveHelpers.Effectful.cast_info_to_propositions"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions. | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition) | [] | FStar.InteractiveHelpers.Effectful.cast_info_list_to_propositions | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
ls: Prims.list FStar.InteractiveHelpers.Effectful.cast_info
-> FStar.Tactics.Effect.Tac (Prims.list FStar.InteractiveHelpers.Propositions.proposition) | {
"end_col": 13,
"end_line": 349,
"start_col": 46,
"start_line": 347
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None | let is_let_st_get dbg (t: term_view) = | true | null | false | print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.V1.Data.term_view",
"Prims.list",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.is_st_get",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Tactics.V1.Builtins.pack"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_let_st_get : dbg: Prims.bool -> t: FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.Reflection.Types.bv * FStar.Reflection.Types.typ)) | [] | FStar.InteractiveHelpers.Effectful.is_let_st_get | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> t: FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.Reflection.Types.bv * FStar.Reflection.Types.typ)) | {
"end_col": 8,
"end_line": 535,
"start_col": 2,
"start_line": 528
} |
|
FStar.Tactics.Effect.Tac | val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown | val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post = | true | null | false | print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.PP_Pure",
"FStar.InteractiveHelpers.Effectful.pre_post_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.InteractiveHelpers.Effectful.PP_State",
"FStar.InteractiveHelpers.Effectful.PP_Unknown",
"FStar.InteractiveHelpers.Effectful.term_eq",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.Effectful.compute_post_type",
"FStar.InteractiveHelpers.Effectful.compute_pre_type"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type | [] | FStar.InteractiveHelpers.Effectful.check_pre_post_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
e: FStar.Reflection.Types.env ->
pre: FStar.Reflection.Types.term ->
ret_type: FStar.Reflection.Types.term ->
post: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.InteractiveHelpers.Effectful.pre_post_type | {
"end_col": 14,
"end_line": 457,
"start_col": 2,
"start_line": 447
} |
Prims.Tot | val get_refinement (ty: type_info{Some? ty.refin}) : Tot term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin | val get_refinement (ty: type_info{Some? ty.refin}) : Tot term
let get_refinement (ty: type_info{Some? ty.refin}) : Tot term = | false | null | false | Some?.v ty.refin | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__refin",
"FStar.Pervasives.Native.__proj__Some__item__v"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_refinement (ty: type_info{Some? ty.refin}) : Tot term | [] | FStar.InteractiveHelpers.Effectful.get_refinement | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ty: FStar.InteractiveHelpers.ExploreTerm.type_info{Some? (Mktype_info?.refin ty)}
-> FStar.Reflection.Types.term | {
"end_col": 18,
"end_line": 230,
"start_col": 2,
"start_line": 230
} |
FStar.Tactics.Effect.Tac | val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge | val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm = | true | null | false | match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful._introduce_variables_for_abs",
"FStar.Pervasives.Native.tuple3",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Pervasives.Native.Mktuple3",
"Prims.Nil",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.safe_tc",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv) | [] | FStar.InteractiveHelpers.Effectful.introduce_variables_for_abs | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ge: FStar.InteractiveHelpers.Base.genv -> tm: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Prims.list FStar.Reflection.Types.term * Prims.list FStar.Reflection.Types.binder) *
FStar.InteractiveHelpers.Base.genv) | {
"end_col": 22,
"end_line": 495,
"start_col": 2,
"start_line": 493
} |
Prims.Tot | val effect_type_is_stateful : effect_type -> Tot bool | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true | val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype = | false | null | false | match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.ExploreTerm.effect_type",
"Prims.bool"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val effect_type_is_stateful : effect_type -> Tot bool | [] | FStar.InteractiveHelpers.Effectful.effect_type_is_stateful | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | etype: FStar.InteractiveHelpers.ExploreTerm.effect_type -> Prims.bool | {
"end_col": 38,
"end_line": 508,
"start_col": 2,
"start_line": 506
} |
FStar.Tactics.Effect.Tac | val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e | val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
let compute_eterm_info (dbg: bool) (e: env) (t: term) = | true | null | false | let hd, parameters = decompose_application e t in
try
let c:comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo -> mk_eterm_info einfo hd parameters
with
| TacticFailure msg -> mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.Effectful.eterm_info",
"Prims.unit",
"FStar.InteractiveHelpers.Base.mfail",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.InteractiveHelpers.Effectful.mk_eterm_info",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.comp_to_effect_info",
"FStar.Reflection.Types.comp",
"FStar.InteractiveHelpers.Effectful.tcc_no_lift",
"Prims.exn",
"FStar.Tactics.Effect.raise",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Effectful.decompose_application"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info | [] | FStar.InteractiveHelpers.Effectful.compute_eterm_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> e: FStar.Reflection.Types.env -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.InteractiveHelpers.Effectful.eterm_info | {
"end_col": 16,
"end_line": 220,
"start_col": 58,
"start_line": 205
} |
FStar.Tactics.Effect.Tac | val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None | val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post = | true | null | false | print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.Effectful.pre_post_type",
"FStar.InteractiveHelpers.Effectful.check_pre_post_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.InteractiveHelpers.Effectful.compute_pre_type",
"FStar.InteractiveHelpers.Effectful.compute_post_type",
"FStar.Pervasives.Native.None"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type) | [] | FStar.InteractiveHelpers.Effectful.check_opt_pre_post_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
e: FStar.Reflection.Types.env ->
opt_pre: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
ret_type: FStar.Reflection.Types.term ->
opt_post: FStar.Pervasives.Native.option FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option FStar.InteractiveHelpers.Effectful.pre_post_type) | {
"end_col": 8,
"end_line": 474,
"start_col": 2,
"start_line": 461
} |
FStar.Tactics.Effect.Tac | val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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 find_mem_in_children dbg ge child =
(* We stop whenever we find an expression which is not a let-binding *)
match inspect child with
| Tv_Let recf attrs bv ty def body ->
if is_st_get dbg def then ge, Some bv
else if term_has_effectful_comp dbg ge.env def <> Some false then ge, None
else
let ge1 = genv_push_bv ge bv ty false None in
find_mem_in_children dbg ge1 body
| _ -> ge, None | val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv)
let rec find_mem_in_children dbg ge child = | true | null | false | match inspect child with
| Tv_Let recf attrs bv ty def body ->
if is_st_get dbg def
then ge, Some bv
else
if term_has_effectful_comp dbg ge.env def <> Some false
then ge, None
else
let ge1 = genv_push_bv ge bv ty false None in
find_mem_in_children dbg ge1 body
| _ -> ge, None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.None",
"FStar.InteractiveHelpers.Effectful.find_mem_in_children",
"FStar.InteractiveHelpers.Base.genv_push_bv",
"Prims.op_disEquality",
"FStar.InteractiveHelpers.Effectful.term_has_effectful_comp",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.InteractiveHelpers.Effectful.is_st_get",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false
let is_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None
// TODO: Define relation between parents and children in and use it in explore_term
// app: head or arg
// let : bv or def or child
// match: scrutinee or branch
// ascribed: e or ty
/// Check if a term's computation is effectful. The return type is option
/// because we may not be able to retrieve the term computation.
val term_has_effectful_comp : bool -> env -> term -> Tac (option bool)
let term_has_effectful_comp dbg e tm =
print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None
/// Check if a related term is effectful. This is used to look for instances of
/// ``HS.mem`` to instantiate pre/postconditions, which means that the term should
/// be a parent/child term of the term under study, as generated by ``explore_term``
/// (otherwise the way we check that a term is effectful doesn't make sense).
/// The computation is an overapproximation: it may happen that, for instance, we
/// can't compute a term computation. In this case, we consider that the term is
/// effectful. There are also situations in which we may not be sure which term to
/// consider.
let related_term_is_effectul dbg ge tv : Tac bool =
let is_effectful tm =
term_has_effectful_comp dbg ge.env tm <> Some false
in
match tv with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> false
| Tv_App hd (a, qual) ->
(* The term under focus should be the app itself or an argument *)
false
| Tv_Abs br body -> false
| Tv_Arrow br c0 -> false
| Tv_Type _ -> false
| Tv_Refine bv sort ref ->
false
| Tv_Const _ -> false
| Tv_Uvar _ _ -> false
| Tv_Let recf attrs bv ty def body -> is_effectful def
| Tv_Match scrutinee _ret_opt branches ->
(* TODO: we need to keep track of the relation between parents and children *)
(* We assume the term under focus is in one the branches of the match - this
* assumption is safe: in the worst case, we won't be able to find a mem to use.
* Besides, in practice it is uncommon (impossible?) to use an effectful term
* as the scrutinee of a match *)
is_effectful scrutinee
| Tv_AscribedT e ty tac _ -> false (* The focused term should be inside the ascription *)
| Tv_AscribedC e c tac _ -> false (* The focused term should be inside the ascription *)
| _ -> (* Unknown: keep things safe *) true
/// Look for a term of the form ``let h = ST.get ()`` in a list of parent/children terms
/// and return the let-bound bv. Abort the search if we find a non-effectful term.
/// The typical usages of this function are the following:
/// - look for a state variable to instantiate the precondition of the term under focus
/// - look for state variables for the pre/postconditions of a term defined before
/// the term under focus.
val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ))
let rec find_mem_in_related dbg ge tms =
match tms with
| [] -> None
| tv :: tms' ->
print_dbg dbg ("[> find_mem_in_related:\n" ^ term_to_string tv);
match is_let_st_get dbg tv with
| Some bvt ->
print_dbg dbg "Term is of the form `let x = FStar.HyperStack.ST.get ()`: success";
Some bvt
| None ->
print_dbg dbg "Term is not of the form `let x = FStar.HyperStack.ST.get ()`: continuing";
if related_term_is_effectul dbg ge tv
then
begin
print_dbg dbg "Term is effectful: stopping here";
None
end
else
begin
print_dbg dbg "Term is not effectful: continuing";
find_mem_in_related dbg ge tms'
end
// TODO: not used for now
/// Look for a term of the form ``let h = ST.get ()`` in a child term (the
/// focused term is supposed to be a subterm of the definition of a let-construct).
val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv)
let rec find_mem_in_children dbg ge child = | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv) | [
"recursion"
] | FStar.InteractiveHelpers.Effectful.find_mem_in_children | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> ge: FStar.InteractiveHelpers.Base.genv -> child: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.Base.genv * FStar.Pervasives.Native.option FStar.Reflection.Types.bv) | {
"end_col": 17,
"end_line": 646,
"start_col": 2,
"start_line": 639
} |
FStar.Tactics.Effect.Tac | val typ_or_comp_to_effect_info (dbg: bool) (ge: genv) (c: typ_or_comp) : Tac effect_info | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo | val typ_or_comp_to_effect_info (dbg: bool) (ge: genv) (c: typ_or_comp) : Tac effect_info
let typ_or_comp_to_effect_info (dbg: bool) (ge: genv) (c: typ_or_comp) : Tac effect_info = | true | null | false | let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.Reflection.Types.typ",
"Prims.list",
"FStar.Reflection.Types.binder",
"Prims.nat",
"FStar.InteractiveHelpers.Effectful.mk_effect_info",
"FStar.InteractiveHelpers.ExploreTerm.E_Total",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type",
"FStar.Reflection.Types.comp",
"FStar.InteractiveHelpers.Base.mfail",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.acomp_to_string",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.comp_to_effect_info",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.InteractiveHelpers.ExploreTerm.num_unflushed_of_typ_or_comp",
"FStar.InteractiveHelpers.ExploreTerm.flush_typ_or_comp",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``. | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val typ_or_comp_to_effect_info (dbg: bool) (ge: genv) (c: typ_or_comp) : Tac effect_info | [] | FStar.InteractiveHelpers.Effectful.typ_or_comp_to_effect_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
c: FStar.InteractiveHelpers.ExploreTerm.typ_or_comp
-> FStar.Tactics.Effect.Tac FStar.InteractiveHelpers.Effectful.effect_info | {
"end_col": 25,
"end_line": 179,
"start_col": 19,
"start_line": 160
} |
FStar.Tactics.Effect.Tac | val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None | val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm = | true | null | false | match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.comp",
"FStar.InteractiveHelpers.Effectful.comp_to_effect_info",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.Pervasives.Native.None",
"FStar.InteractiveHelpers.ExploreTerm.safe_tcc"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info) | [] | FStar.InteractiveHelpers.Effectful.compute_effect_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> e: FStar.Reflection.Types.env -> tm: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option FStar.InteractiveHelpers.Effectful.effect_info) | {
"end_col": 16,
"end_line": 155,
"start_col": 2,
"start_line": 153
} |
FStar.Tactics.Effect.Tac | val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge | val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm = | true | null | false | match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Base.genv",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.introduce_variables_for_abs",
"FStar.Pervasives.Native.tuple3",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Pervasives.Native.Mktuple3",
"Prims.Nil"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv) | [] | FStar.InteractiveHelpers.Effectful.introduce_variables_for_opt_abs | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
ge: FStar.InteractiveHelpers.Base.genv ->
opt_tm: FStar.Pervasives.Native.option FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Prims.list FStar.Reflection.Types.term * Prims.list FStar.Reflection.Types.binder) *
FStar.InteractiveHelpers.Base.genv) | {
"end_col": 22,
"end_line": 501,
"start_col": 2,
"start_line": 499
} |
FStar.Tactics.Effect.Tac | val term_has_effectful_comp : bool -> env -> term -> Tac (option bool) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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_has_effectful_comp dbg e tm =
print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None | val term_has_effectful_comp : bool -> env -> term -> Tac (option bool)
let term_has_effectful_comp dbg e tm = | true | null | false | print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.Pervasives.Native.Some",
"Prims.op_Negation",
"FStar.InteractiveHelpers.ExploreTerm.effect_type_is_pure",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_type",
"FStar.Pervasives.Native.option",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.op_Hat",
"FStar.InteractiveHelpers.ExploreTerm.effect_type_to_string",
"FStar.Pervasives.Native.None",
"FStar.InteractiveHelpers.Effectful.compute_effect_info"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false
let is_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None
// TODO: Define relation between parents and children in and use it in explore_term
// app: head or arg
// let : bv or def or child
// match: scrutinee or branch
// ascribed: e or ty
/// Check if a term's computation is effectful. The return type is option
/// because we may not be able to retrieve the term computation.
val term_has_effectful_comp : bool -> env -> term -> Tac (option bool) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val term_has_effectful_comp : bool -> env -> term -> Tac (option bool) | [] | FStar.InteractiveHelpers.Effectful.term_has_effectful_comp | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> e: FStar.Reflection.Types.env -> tm: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.bool) | {
"end_col": 8,
"end_line": 555,
"start_col": 2,
"start_line": 547
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown" | let type_comparison_to_string c = | false | null | false | match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown" | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.Effectful.type_comparison",
"Prims.string"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1" | false | true | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val type_comparison_to_string : c: FStar.InteractiveHelpers.Effectful.type_comparison -> Prims.string | [] | FStar.InteractiveHelpers.Effectful.type_comparison_to_string | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | c: FStar.InteractiveHelpers.Effectful.type_comparison -> Prims.string | {
"end_col": 24,
"end_line": 246,
"start_col": 2,
"start_line": 243
} |
|
FStar.Tactics.Effect.Tac | val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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 _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge | val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty = | true | null | false | match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
(match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1)
| _ -> [], [], ge | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.InteractiveHelpers.ExploreTerm.get_total_or_gtotal_ret_type",
"Prims.list",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.Mktuple3",
"Prims.Cons",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Effectful._introduce_variables_for_abs",
"Prims.Nil",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Derived.bv_of_binder",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Base.genv_push_fresh_binder",
"FStar.Reflection.V1.Derived.type_of_binder",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Derived.name_of_binder",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv) | [
"recursion"
] | FStar.InteractiveHelpers.Effectful._introduce_variables_for_abs | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ge: FStar.InteractiveHelpers.Base.genv -> ty: FStar.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac
((Prims.list FStar.Reflection.Types.term * Prims.list FStar.Reflection.Types.binder) *
FStar.InteractiveHelpers.Base.genv) | {
"end_col": 18,
"end_line": 489,
"start_col": 2,
"start_line": 478
} |
FStar.Tactics.Effect.Tac | val compute_pre_type : bool -> env -> term -> Tac pre_post_type | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown | val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre = | true | null | false | print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.PP_Unknown",
"FStar.InteractiveHelpers.Effectful.pre_post_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.ExploreTerm.is_total_or_gtotal",
"FStar.InteractiveHelpers.Effectful.PP_Pure",
"FStar.InteractiveHelpers.Effectful.PP_State",
"FStar.Reflection.V1.Derived.type_of_binder",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Pervasives.Native.tuple2",
"Prims.string_of_int",
"FStar.List.Tot.Base.length",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr_bs",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.safe_tc"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_pre_type : bool -> env -> term -> Tac pre_post_type | [] | FStar.InteractiveHelpers.Effectful.compute_pre_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> e: FStar.Reflection.Types.env -> pre: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.InteractiveHelpers.Effectful.pre_post_type | {
"end_col": 16,
"end_line": 385,
"start_col": 2,
"start_line": 367
} |
FStar.Tactics.Effect.Tac | val compare_cast_types (dbg: bool) (p: cast_info)
: Tac
(c:
type_comparison
{ ((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty)) }) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown | val compare_cast_types (dbg: bool) (p: cast_info)
: Tac
(c:
type_comparison
{ ((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty)) })
let compare_cast_types (dbg: bool) (p: cast_info)
: Tac
(c:
type_comparison
{ ((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty)) }) = | true | null | false | print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 -> compare_types dbg info1 info2
| _ -> Unknown | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__p_ty",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__exp_ty",
"FStar.InteractiveHelpers.Effectful.compare_types",
"FStar.InteractiveHelpers.Effectful.type_comparison",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"FStar.InteractiveHelpers.Effectful.Same_raw_type",
"FStar.InteractiveHelpers.Effectful.has_refinement",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Effectful.Unknown",
"Prims.l_and",
"Prims.l_or",
"FStar.InteractiveHelpers.Effectful.Refines",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\ | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_cast_types (dbg: bool) (p: cast_info)
: Tac
(c:
type_comparison
{ ((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty)) }) | [] | FStar.InteractiveHelpers.Effectful.compare_cast_types | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> p: FStar.InteractiveHelpers.Effectful.cast_info
-> FStar.Tactics.Effect.Tac
(c:
FStar.InteractiveHelpers.Effectful.type_comparison
{ (c = FStar.InteractiveHelpers.Effectful.Refines \/
c = FStar.InteractiveHelpers.Effectful.Same_raw_type ==>
Some? (Mkcast_info?.p_ty p) /\ Some? (Mkcast_info?.exp_ty p)) /\
(c = FStar.InteractiveHelpers.Effectful.Same_raw_type ==>
FStar.InteractiveHelpers.Effectful.has_refinement (Some?.v (Mkcast_info?.exp_ty p))) }) | {
"end_col": 16,
"end_line": 286,
"start_col": 2,
"start_line": 282
} |
FStar.Tactics.Effect.Tac | val decompose_application_aux (e: env) (t: term) : Tac (term & list cast_info) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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 decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, [] | val decompose_application_aux (e: env) (t: term) : Tac (term & list cast_info)
let rec decompose_application_aux (e: env) (t: term) : Tac (term & list cast_info) = | true | null | false | match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
let a_type = get_type_info e a in
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c -> Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, [] | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Data.aqualv",
"Prims.list",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Cons",
"FStar.InteractiveHelpers.Effectful.mk_cast_info",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type",
"FStar.Reflection.Types.typ",
"FStar.Tactics.V1.Derived.binder_sort",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.ExploreTerm.safe_tc",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info",
"FStar.InteractiveHelpers.Effectful.decompose_application_aux",
"Prims.Nil"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) : | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val decompose_application_aux (e: env) (t: term) : Tac (term & list cast_info) | [
"recursion"
] | FStar.InteractiveHelpers.Effectful.decompose_application_aux | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | e: FStar.Reflection.Types.env -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Reflection.Types.term * Prims.list FStar.InteractiveHelpers.Effectful.cast_info) | {
"end_col": 14,
"end_line": 101,
"start_col": 2,
"start_line": 83
} |
FStar.Tactics.Effect.Tac | val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> [] | val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci = | true | null | false | print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> [] | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.Effectful.cast_info",
"Prims.Nil",
"FStar.InteractiveHelpers.Propositions.proposition",
"Prims.list",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.Cons",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Base.mk_app_norm",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__term",
"FStar.InteractiveHelpers.Effectful.get_refinement",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__exp_ty",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Effectful.__proj__Mkcast_info__item__p_ty",
"FStar.InteractiveHelpers.Base.opt_cons",
"FStar.InteractiveHelpers.Base.opt_mk_app_norm",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__refin",
"FStar.Reflection.V1.Derived.mk_app",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.Q_Implicit",
"FStar.Reflection.V1.Data.Q_Explicit",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_AscribedT",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.Effectful.get_rawest_type",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Effectful.type_comparison",
"Prims.l_and",
"Prims.l_imp",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"FStar.InteractiveHelpers.Effectful.Refines",
"FStar.InteractiveHelpers.Effectful.Same_raw_type",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.InteractiveHelpers.Effectful.has_refinement",
"FStar.InteractiveHelpers.Effectful.compare_cast_types",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Effectful.cast_info_to_string"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition) | [] | FStar.InteractiveHelpers.Effectful.cast_info_to_propositions | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
ci: FStar.InteractiveHelpers.Effectful.cast_info
-> FStar.Tactics.Effect.Tac (Prims.list FStar.InteractiveHelpers.Propositions.proposition) | {
"end_col": 13,
"end_line": 341,
"start_col": 2,
"start_line": 313
} |
FStar.Tactics.Effect.Tac | val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_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 find_mem_in_related dbg ge tms =
match tms with
| [] -> None
| tv :: tms' ->
print_dbg dbg ("[> find_mem_in_related:\n" ^ term_to_string tv);
match is_let_st_get dbg tv with
| Some bvt ->
print_dbg dbg "Term is of the form `let x = FStar.HyperStack.ST.get ()`: success";
Some bvt
| None ->
print_dbg dbg "Term is not of the form `let x = FStar.HyperStack.ST.get ()`: continuing";
if related_term_is_effectul dbg ge tv
then
begin
print_dbg dbg "Term is effectful: stopping here";
None
end
else
begin
print_dbg dbg "Term is not effectful: continuing";
find_mem_in_related dbg ge tms'
end | val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ))
let rec find_mem_in_related dbg ge tms = | true | null | false | match tms with
| [] -> None
| tv :: tms' ->
print_dbg dbg ("[> find_mem_in_related:\n" ^ term_to_string tv);
match is_let_st_get dbg tv with
| Some bvt ->
print_dbg dbg "Term is of the form `let x = FStar.HyperStack.ST.get ()`: success";
Some bvt
| None ->
print_dbg dbg "Term is not of the form `let x = FStar.HyperStack.ST.get ()`: continuing";
if related_term_is_effectul dbg ge tv
then
(print_dbg dbg "Term is effectful: stopping here";
None)
else
(print_dbg dbg "Term is not effectful: continuing";
find_mem_in_related dbg ge tms') | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.InteractiveHelpers.Effectful.find_mem_in_related",
"FStar.InteractiveHelpers.Effectful.related_term_is_effectul",
"FStar.InteractiveHelpers.Effectful.is_let_st_get",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.pack"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false
let is_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None
// TODO: Define relation between parents and children in and use it in explore_term
// app: head or arg
// let : bv or def or child
// match: scrutinee or branch
// ascribed: e or ty
/// Check if a term's computation is effectful. The return type is option
/// because we may not be able to retrieve the term computation.
val term_has_effectful_comp : bool -> env -> term -> Tac (option bool)
let term_has_effectful_comp dbg e tm =
print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None
/// Check if a related term is effectful. This is used to look for instances of
/// ``HS.mem`` to instantiate pre/postconditions, which means that the term should
/// be a parent/child term of the term under study, as generated by ``explore_term``
/// (otherwise the way we check that a term is effectful doesn't make sense).
/// The computation is an overapproximation: it may happen that, for instance, we
/// can't compute a term computation. In this case, we consider that the term is
/// effectful. There are also situations in which we may not be sure which term to
/// consider.
let related_term_is_effectul dbg ge tv : Tac bool =
let is_effectful tm =
term_has_effectful_comp dbg ge.env tm <> Some false
in
match tv with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> false
| Tv_App hd (a, qual) ->
(* The term under focus should be the app itself or an argument *)
false
| Tv_Abs br body -> false
| Tv_Arrow br c0 -> false
| Tv_Type _ -> false
| Tv_Refine bv sort ref ->
false
| Tv_Const _ -> false
| Tv_Uvar _ _ -> false
| Tv_Let recf attrs bv ty def body -> is_effectful def
| Tv_Match scrutinee _ret_opt branches ->
(* TODO: we need to keep track of the relation between parents and children *)
(* We assume the term under focus is in one the branches of the match - this
* assumption is safe: in the worst case, we won't be able to find a mem to use.
* Besides, in practice it is uncommon (impossible?) to use an effectful term
* as the scrutinee of a match *)
is_effectful scrutinee
| Tv_AscribedT e ty tac _ -> false (* The focused term should be inside the ascription *)
| Tv_AscribedC e c tac _ -> false (* The focused term should be inside the ascription *)
| _ -> (* Unknown: keep things safe *) true
/// Look for a term of the form ``let h = ST.get ()`` in a list of parent/children terms
/// and return the let-bound bv. Abort the search if we find a non-effectful term.
/// The typical usages of this function are the following:
/// - look for a state variable to instantiate the precondition of the term under focus
/// - look for state variables for the pre/postconditions of a term defined before
/// the term under focus.
val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ)) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ)) | [
"recursion"
] | FStar.InteractiveHelpers.Effectful.find_mem_in_related | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
tms: Prims.list FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.Reflection.Types.bv * FStar.Reflection.Types.typ)) | {
"end_col": 11,
"end_line": 626,
"start_col": 2,
"start_line": 606
} |
FStar.Tactics.Effect.Tac | val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end | val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv = | true | null | false | match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x, a) -> (prettify_term dbg x, a)) eff_args in
match etype, eff_args with
| E_PURE, [pre, _] -> Some (mk_res (Some pre) None)
| E_Pure, [pre, _ ; post, _]
| E_Stack, [pre, _ ; post, _]
| E_ST, [pre, _ ; post, _] -> Some (mk_res (Some pre) (Some post))
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [pre, _] -> Some (mk_res (Some pre) None)
| E_Unknown, [pre, _ ; post, _] -> Some (mk_res (Some pre) (Some post))
| _ -> None | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.V1.Data.comp_view",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.InteractiveHelpers.Effectful.mk_effect_info",
"FStar.InteractiveHelpers.ExploreTerm.E_Total",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type",
"FStar.InteractiveHelpers.ExploreTerm.E_Lemma",
"FStar.InteractiveHelpers.ExploreTerm.unit_type_info",
"FStar.InteractiveHelpers.Base.prettify_term",
"FStar.Reflection.V1.Data.universes",
"FStar.Reflection.Types.name",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.ExploreTerm.effect_type",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Tactics.Util.map",
"FStar.InteractiveHelpers.ExploreTerm.effect_name_to_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.op_Hat",
"FStar.Reflection.V1.Derived.flatten_name"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info) | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info) | [] | FStar.InteractiveHelpers.Effectful.comp_view_to_effect_info | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> cv: FStar.Reflection.V1.Data.comp_view
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option FStar.InteractiveHelpers.Effectful.effect_info) | {
"end_col": 7,
"end_line": 142,
"start_col": 2,
"start_line": 112
} |
FStar.Tactics.Effect.Tac | val compare_types (dbg: bool) (info1 info2: type_info)
: Tac (c: type_comparison{c = Same_raw_type ==> has_refinement info2}) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown | val compare_types (dbg: bool) (info1 info2: type_info)
: Tac (c: type_comparison{c = Same_raw_type ==> has_refinement info2})
let compare_types (dbg: bool) (info1 info2: type_info)
: Tac (c: type_comparison{c = Same_raw_type ==> has_refinement info2}) = | true | null | false | print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty
then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2
then
let _ = print_dbg dbg "-> 2nd type has refinement" in
if has_refinement info1
then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2)
then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines
else
let _ = print_dbg dbg "types are not equal" in
Unknown | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.Effectful.has_refinement",
"FStar.InteractiveHelpers.Effectful.Refines",
"FStar.InteractiveHelpers.Effectful.type_comparison",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"FStar.InteractiveHelpers.Effectful.Same_raw_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.InteractiveHelpers.Effectful.term_eq",
"FStar.InteractiveHelpers.Effectful.get_refinement",
"FStar.InteractiveHelpers.Effectful.Unknown",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__ty"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) : | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_types (dbg: bool) (info1 info2: type_info)
: Tac (c: type_comparison{c = Same_raw_type ==> has_refinement info2}) | [] | FStar.InteractiveHelpers.Effectful.compare_types | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
info1: FStar.InteractiveHelpers.ExploreTerm.type_info ->
info2: FStar.InteractiveHelpers.ExploreTerm.type_info
-> FStar.Tactics.Effect.Tac
(c:
FStar.InteractiveHelpers.Effectful.type_comparison
{ c = FStar.InteractiveHelpers.Effectful.Same_raw_type ==>
FStar.InteractiveHelpers.Effectful.has_refinement info2 }) | {
"end_col": 13,
"end_line": 276,
"start_col": 2,
"start_line": 252
} |
FStar.Tactics.Effect.Tac | val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown | val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post = | true | null | false | print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [s1 ; r ; s2], true ->
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg
("- ret type:\n-- target: " ^ term_to_string ret_type ^ "\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg
("- state types:\n-- binder1: " ^
term_to_string s1_ty ^ "\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
(print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1))
else
(print_dbg dbg "PP_Unknown";
PP_Unknown)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.PP_Unknown",
"FStar.InteractiveHelpers.Effectful.pre_post_type",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.ExploreTerm.is_total_or_gtotal",
"FStar.InteractiveHelpers.Effectful.PP_Pure",
"Prims.op_AmpAmp",
"FStar.InteractiveHelpers.Effectful.PP_State",
"FStar.Reflection.V1.Derived.type_of_binder",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"Prims.string_of_bool",
"FStar.InteractiveHelpers.Effectful.term_eq",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.Effectful.opt_remove_refin",
"FStar.Pervasives.Native.tuple2",
"Prims.string_of_int",
"FStar.List.Tot.Base.length",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr_bs",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.safe_tc",
"FStar.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.ExploreTerm.get_total_or_gtotal_ret_type",
"FStar.Pervasives.Native.Some",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.Pervasives.Native.None"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type | [] | FStar.InteractiveHelpers.Effectful.compute_post_type | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
e: FStar.Reflection.Types.env ->
ret_type: FStar.Reflection.Types.term ->
post: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.InteractiveHelpers.Effectful.pre_post_type | {
"end_col": 16,
"end_line": 443,
"start_col": 2,
"start_line": 395
} |
FStar.Tactics.Effect.Tac | val pre_post_to_propositions :
dbg:bool
-> ge:genv
-> etype:effect_type
-> ret_value:term
-> ret_abs_binder:option binder
-> ret_type:type_info
-> opt_pre:option term
-> opt_post:option term
-> parents:list term_view (* to look for state variables for the pre *)
-> children:list term_view (* to look for state variables for the pre and post *)
-> Tac (genv & option proposition & option proposition) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pre_post_to_propositions dbg ge0 etype v ret_abs_binder ret_type opt_pre opt_post
parents children =
print_dbg dbg "[> pre_post_to_propositions: begin";
print_dbg dbg ("- uninstantiated pre: " ^ option_to_string term_to_string opt_pre);
print_dbg dbg ("- uninstantiated post: " ^ option_to_string term_to_string opt_post);
let brs = match ret_abs_binder with | None -> [] | Some b -> [b] in
(* Analyze the pre and the postcondition and introduce the necessary variables *)
let ge3, (pre_values, pre_binders), (post_values, post_binders) =
match etype with
| E_Lemma ->
print_dbg dbg "E_Lemma";
ge0, ([], []), ([(`())], [])
| E_Total | E_GTotal ->
print_dbg dbg "E_Total/E_GTotal";
ge0, ([], []), ([], [])
| E_PURE | E_Pure ->
print_dbg dbg "E_PURE/E_Pure";
ge0, ([], []), ([v], brs)
| E_Stack | E_ST ->
print_dbg dbg "E_Stack/E_ST";
(* Look for state variables in the context *)
print_dbg dbg "Looking for the initial state in the context";
let b1_opt = find_mem_in_related dbg ge0 parents in
print_dbg dbg "Looking for the final state in the context";
let b2_opt = find_mem_in_related dbg ge0 children in
(* Introduce state variables if necessary *)
let opt_push_fresh_state opt_bvt basename ge : Tac (term & binder & genv) =
match opt_bvt with
| Some (bv, ty) -> pack (Tv_Var bv), mk_binder bv ty, ge
| None -> genv_push_fresh_var ge basename (`HS.mem)
in
let h1, b1, ge1 = opt_push_fresh_state b1_opt "__h0_" ge0 in
let h2, b2, ge2 = opt_push_fresh_state b2_opt "__h1_" ge1 in
ge2, ([h1], [b1]), ([h1; v; h2], List.Tot.flatten ([b1]::brs::[[b2]]))
| E_Unknown ->
(* We don't know what the effect is and the current pre and post-conditions
* are currently guesses. Introduce any necessary variable abstracted by
* those parameters *)
(* The pre and post-conditions are likely to have the same shape as
* one of Pure or Stack (depending on whether we use or not an internal
* state). We try to check that and to instantiate them accordingly *)
let pp_type = check_opt_pre_post_type dbg ge0.env opt_pre ret_type.ty opt_post in
begin match pp_type with
| Some PP_Pure ->
print_dbg dbg "PP_Pure";
(* We only need the return value *)
ge0, ([], []), ([v], brs)
| Some (PP_State state_type) ->
print_dbg dbg "PP_State";
(* Introduce variables for the states *)
let s1, b1, s2, b2, ge1 = genv_push_two_fresh_vars ge0 "__s" state_type in
ge1, ([s1], [b1]), ([s1; v; s2], List.Tot.flatten ([b1]::brs::[[b2]]))
| Some PP_Unknown ->
print_dbg dbg "PP_Unknown";
(* Introduce variables for all the values, for the pre and the post *)
let pre_values, pre_binders, ge1 = introduce_variables_for_opt_abs ge0 opt_pre in
let post_values, post_binders, ge1 = introduce_variables_for_opt_abs ge1 opt_post in
ge1, (pre_values, pre_binders), (post_values, post_binders)
| _ ->
print_dbg dbg "No pre and no post";
(* No pre and no post *)
ge0, ([], []), ([], [])
end
in
(* Generate the propositions: *)
(* - from the precondition *)
let pre_prop = opt_mk_app_norm ge3.env opt_pre pre_values in
(* - from the postcondition - note that in the case of a global post-condition
* we might try to instantiate the return variable with a variable whose
* type is not correct, leading to an error. We thus catch errors below and
* drop the post if there is a problem *)
let post_prop =
try opt_mk_app_norm ge3.env opt_post post_values
with
| _ ->
print_dbg dbg "Dropping a postcondition because of incoherent typing";
None
in
(* return *)
print_dbg dbg "[> pre_post_to_propositions: end";
ge3, pre_prop, post_prop | val pre_post_to_propositions :
dbg:bool
-> ge:genv
-> etype:effect_type
-> ret_value:term
-> ret_abs_binder:option binder
-> ret_type:type_info
-> opt_pre:option term
-> opt_post:option term
-> parents:list term_view (* to look for state variables for the pre *)
-> children:list term_view (* to look for state variables for the pre and post *)
-> Tac (genv & option proposition & option proposition)
let pre_post_to_propositions
dbg
ge0
etype
v
ret_abs_binder
ret_type
opt_pre
opt_post
parents
children
= | true | null | false | print_dbg dbg "[> pre_post_to_propositions: begin";
print_dbg dbg ("- uninstantiated pre: " ^ option_to_string term_to_string opt_pre);
print_dbg dbg ("- uninstantiated post: " ^ option_to_string term_to_string opt_post);
let brs =
match ret_abs_binder with
| None -> []
| Some b -> [b]
in
let ge3, (pre_values, pre_binders), (post_values, post_binders) =
match etype with
| E_Lemma ->
print_dbg dbg "E_Lemma";
ge0, ([], []), ([(`())], [])
| E_Total
| E_GTotal ->
print_dbg dbg "E_Total/E_GTotal";
ge0, ([], []), ([], [])
| E_PURE
| E_Pure ->
print_dbg dbg "E_PURE/E_Pure";
ge0, ([], []), ([v], brs)
| E_Stack
| E_ST ->
print_dbg dbg "E_Stack/E_ST";
print_dbg dbg "Looking for the initial state in the context";
let b1_opt = find_mem_in_related dbg ge0 parents in
print_dbg dbg "Looking for the final state in the context";
let b2_opt = find_mem_in_related dbg ge0 children in
let opt_push_fresh_state opt_bvt basename ge : Tac (term & binder & genv) =
match opt_bvt with
| Some (bv, ty) -> pack (Tv_Var bv), mk_binder bv ty, ge
| None -> genv_push_fresh_var ge basename (`HS.mem)
in
let h1, b1, ge1 = opt_push_fresh_state b1_opt "__h0_" ge0 in
let h2, b2, ge2 = opt_push_fresh_state b2_opt "__h1_" ge1 in
ge2, ([h1], [b1]), ([h1; v; h2], List.Tot.flatten ([[b1]; brs; [b2]]))
| E_Unknown ->
let pp_type = check_opt_pre_post_type dbg ge0.env opt_pre ret_type.ty opt_post in
match pp_type with
| Some PP_Pure ->
print_dbg dbg "PP_Pure";
ge0, ([], []), ([v], brs)
| Some (PP_State state_type) ->
print_dbg dbg "PP_State";
let s1, b1, s2, b2, ge1 = genv_push_two_fresh_vars ge0 "__s" state_type in
ge1, ([s1], [b1]), ([s1; v; s2], List.Tot.flatten ([[b1]; brs; [b2]]))
| Some PP_Unknown ->
print_dbg dbg "PP_Unknown";
let pre_values, pre_binders, ge1 = introduce_variables_for_opt_abs ge0 opt_pre in
let post_values, post_binders, ge1 = introduce_variables_for_opt_abs ge1 opt_post in
ge1, (pre_values, pre_binders), (post_values, post_binders)
| _ ->
print_dbg dbg "No pre and no post";
ge0, ([], []), ([], [])
in
let pre_prop = opt_mk_app_norm ge3.env opt_pre pre_values in
let post_prop =
try opt_mk_app_norm ge3.env opt_post post_values
with
| _ ->
print_dbg dbg "Dropping a postcondition because of incoherent typing";
None
in
print_dbg dbg "[> pre_post_to_propositions: end";
ge3, pre_prop, post_prop | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.ExploreTerm.effect_type",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.binder",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"Prims.list",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.Mktuple3",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.Pervasives.Native.tuple3",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.Base.opt_mk_app_norm",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"Prims.exn",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Prims.Cons",
"FStar.List.Tot.Base.flatten",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"Prims.string",
"FStar.Reflection.V1.Derived.mk_binder",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.InteractiveHelpers.Base.genv_push_fresh_var",
"FStar.InteractiveHelpers.Effectful.find_mem_in_related",
"FStar.Pervasives.Native.tuple5",
"FStar.InteractiveHelpers.Base.genv_push_two_fresh_vars",
"FStar.InteractiveHelpers.Effectful.introduce_variables_for_opt_abs",
"FStar.InteractiveHelpers.Effectful.pre_post_type",
"FStar.InteractiveHelpers.Effectful.check_opt_pre_post_type",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__ty",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.Tactics.V1.Builtins.term_to_string"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false
let is_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None
// TODO: Define relation between parents and children in and use it in explore_term
// app: head or arg
// let : bv or def or child
// match: scrutinee or branch
// ascribed: e or ty
/// Check if a term's computation is effectful. The return type is option
/// because we may not be able to retrieve the term computation.
val term_has_effectful_comp : bool -> env -> term -> Tac (option bool)
let term_has_effectful_comp dbg e tm =
print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None
/// Check if a related term is effectful. This is used to look for instances of
/// ``HS.mem`` to instantiate pre/postconditions, which means that the term should
/// be a parent/child term of the term under study, as generated by ``explore_term``
/// (otherwise the way we check that a term is effectful doesn't make sense).
/// The computation is an overapproximation: it may happen that, for instance, we
/// can't compute a term computation. In this case, we consider that the term is
/// effectful. There are also situations in which we may not be sure which term to
/// consider.
let related_term_is_effectul dbg ge tv : Tac bool =
let is_effectful tm =
term_has_effectful_comp dbg ge.env tm <> Some false
in
match tv with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> false
| Tv_App hd (a, qual) ->
(* The term under focus should be the app itself or an argument *)
false
| Tv_Abs br body -> false
| Tv_Arrow br c0 -> false
| Tv_Type _ -> false
| Tv_Refine bv sort ref ->
false
| Tv_Const _ -> false
| Tv_Uvar _ _ -> false
| Tv_Let recf attrs bv ty def body -> is_effectful def
| Tv_Match scrutinee _ret_opt branches ->
(* TODO: we need to keep track of the relation between parents and children *)
(* We assume the term under focus is in one the branches of the match - this
* assumption is safe: in the worst case, we won't be able to find a mem to use.
* Besides, in practice it is uncommon (impossible?) to use an effectful term
* as the scrutinee of a match *)
is_effectful scrutinee
| Tv_AscribedT e ty tac _ -> false (* The focused term should be inside the ascription *)
| Tv_AscribedC e c tac _ -> false (* The focused term should be inside the ascription *)
| _ -> (* Unknown: keep things safe *) true
/// Look for a term of the form ``let h = ST.get ()`` in a list of parent/children terms
/// and return the let-bound bv. Abort the search if we find a non-effectful term.
/// The typical usages of this function are the following:
/// - look for a state variable to instantiate the precondition of the term under focus
/// - look for state variables for the pre/postconditions of a term defined before
/// the term under focus.
val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ))
let rec find_mem_in_related dbg ge tms =
match tms with
| [] -> None
| tv :: tms' ->
print_dbg dbg ("[> find_mem_in_related:\n" ^ term_to_string tv);
match is_let_st_get dbg tv with
| Some bvt ->
print_dbg dbg "Term is of the form `let x = FStar.HyperStack.ST.get ()`: success";
Some bvt
| None ->
print_dbg dbg "Term is not of the form `let x = FStar.HyperStack.ST.get ()`: continuing";
if related_term_is_effectul dbg ge tv
then
begin
print_dbg dbg "Term is effectful: stopping here";
None
end
else
begin
print_dbg dbg "Term is not effectful: continuing";
find_mem_in_related dbg ge tms'
end
// TODO: not used for now
/// Look for a term of the form ``let h = ST.get ()`` in a child term (the
/// focused term is supposed to be a subterm of the definition of a let-construct).
val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv)
let rec find_mem_in_children dbg ge child =
(* We stop whenever we find an expression which is not a let-binding *)
match inspect child with
| Tv_Let recf attrs bv ty def body ->
if is_st_get dbg def then ge, Some bv
else if term_has_effectful_comp dbg ge.env def <> Some false then ge, None
else
let ge1 = genv_push_bv ge bv ty false None in
find_mem_in_children dbg ge1 body
| _ -> ge, None
/// Instantiates optional pre and post conditions
val pre_post_to_propositions :
dbg:bool
-> ge:genv
-> etype:effect_type
-> ret_value:term
-> ret_abs_binder:option binder
-> ret_type:type_info
-> opt_pre:option term
-> opt_post:option term
-> parents:list term_view (* to look for state variables for the pre *)
-> children:list term_view (* to look for state variables for the pre and post *)
-> Tac (genv & option proposition & option proposition)
let pre_post_to_propositions dbg ge0 etype v ret_abs_binder ret_type opt_pre opt_post | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pre_post_to_propositions :
dbg:bool
-> ge:genv
-> etype:effect_type
-> ret_value:term
-> ret_abs_binder:option binder
-> ret_type:type_info
-> opt_pre:option term
-> opt_post:option term
-> parents:list term_view (* to look for state variables for the pre *)
-> children:list term_view (* to look for state variables for the pre and post *)
-> Tac (genv & option proposition & option proposition) | [] | FStar.InteractiveHelpers.Effectful.pre_post_to_propositions | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
etype: FStar.InteractiveHelpers.ExploreTerm.effect_type ->
ret_value: FStar.Reflection.Types.term ->
ret_abs_binder: FStar.Pervasives.Native.option FStar.Reflection.Types.binder ->
ret_type: FStar.InteractiveHelpers.ExploreTerm.type_info ->
opt_pre: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
opt_post: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
parents: Prims.list FStar.Reflection.V1.Data.term_view ->
children: Prims.list FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
((FStar.InteractiveHelpers.Base.genv *
FStar.Pervasives.Native.option FStar.InteractiveHelpers.Propositions.proposition) *
FStar.Pervasives.Native.option FStar.InteractiveHelpers.Propositions.proposition) | {
"end_col": 26,
"end_line": 742,
"start_col": 2,
"start_line": 664
} |
FStar.Tactics.Effect.Tac | val eterm_info_to_assertions :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> ge:genv
-> t:term
-> is_let:bool (* the term is the bound expression in a let binding *)
-> is_assert:bool (* the term is an assert - in which case we only output the precondition *)
-> info:eterm_info
-> opt_bind_var:option term (* if let binding: the bound var *)
-> opt_c:option typ_or_comp
-> parents:list term_view
-> children:list term_view ->
Tac (genv & assertions) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eterm_info_to_assertions dbg with_gpre with_gpost ge t is_let is_assert info bind_var opt_c
parents children =
print_dbg dbg "[> eterm_info_to_assertions";
(* Introduce additional variables to instantiate the return type refinement,
* the precondition, the postcondition and the goal *)
(* First, the return value: returns an updated env, the value to use for
* the return type and a list of abstract binders *)
let einfo = info.einfo in
let ge0, (v : term), (opt_b : option binder) =
match bind_var with
| Some v -> ge, v, None
| None ->
(* If the studied term is stateless, we can use it directly in the
* propositions. If the return value is of type unit, we can just use ().
* Otherwise we need to introduce a variable.
* For the reason why we do this: remember that the studied term might be
* a return value: it is not necessarily bound in a let. *)
if effect_type_is_stateful einfo.ei_type then
if is_unit_type einfo.ei_ret_type.ty then
ge, `(), None
else
let b = fresh_binder ge.env "__ret" einfo.ei_ret_type.ty in
let bv = bv_of_binder b in
let tm = pack (Tv_Var bv) in
genv_push_binder ge b true None, tm, Some b
else ge, t, None
in
(* Generate propositions from the pre and the post-conditions *)
(**) print_dbg dbg "> Instantiating local pre/post";
let ge1, pre_prop, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type v opt_b einfo.ei_ret_type
einfo.ei_pre einfo.ei_post parents children in
print_dbg dbg ("- pre prop: " ^ option_to_string term_to_string pre_prop);
print_dbg dbg ("- post prop: " ^ option_to_string term_to_string post_prop);
(* If the term is an assertion/assumption, only output the postcondition -
* note that in the case of an assertion, the pre and the post are the same,
* but in the case of an assumption, only the post is interesting *)
if is_assert then
begin
print_dbg dbg "The term is an assert: only keep the postcondition";
ge1, { pres = opt_cons post_prop []; posts = [] }
end
else begin
(* Generate propositions from the target computation (pre, post, type cast) *)
let ge2, gparams_props, gpre_prop, gcast_props, gpost_prop =
(* Check if we do the computation (which can be expensive) - note that
* computing the global postcondition makes sense only if the focused
* term is the return value and thus not a let-binding *)
let with_goal : bool = with_gpre || ((not is_let) && with_gpost) in
begin match opt_c, with_goal with
| Some c, true ->
let ei = typ_or_comp_to_effect_info dbg ge1 c in
print_dbg dbg ("- target effect: " ^ effect_info_to_string ei);
print_dbg dbg ("- global unfilt. pre: " ^ option_to_string term_to_string ei.ei_pre);
print_dbg dbg ("- global unfilt. post: " ^ option_to_string term_to_string ei.ei_post);
(* The parameters' type information. To be used only if the variables are not
* shadowed (the parameters themselves, but also the variables inside the refinements) *)
let gparams_props =
begin
if with_gpre then
begin
print_dbg dbg "Generating assertions from the global parameters' types";
print_dbg dbg ("Current genv:\n" ^ genv_to_string ge1);
(* Retrieve the types and pair them with the parameters - note that
* we need to reverse the list of parameters (the outer parameter was
* added first in the list and is thus last) *)
let params =
rev (List.Tot.map (fun x -> (x, type_of_binder x)) (params_of_typ_or_comp c)) in
iteri (fun i (b, _) -> print_dbg dbg ("Global parameter " ^ string_of_int i ^
": " ^ binder_to_string b)) params;
(* Filter the shadowed parameters *)
let params = filter (fun (b, _)-> not (binder_is_shadowed ge1 b)) params in
(* Generate the propositions *)
let param_to_props (x : (binder & typ)) : Tac (list term) =
let b, ty = x in
let bv = bv_of_binder b in
print_dbg dbg ("Generating assertions from global parameter: " ^ binder_to_string b);
let tinfo = get_type_info_from_type ty in
let v = pack (Tv_Var bv) in
let p1 = mk_has_type v tinfo.ty in
let pl = match tinfo.refin with
| None -> []
| Some r ->
let p2 = mk_app_norm ge1.env r [v] in
(* Discard the proposition generated from the type refinement if
* it contains shadowed variables *)
if term_has_shadowed_variables ge1 p2
then begin print_dbg dbg "Discarding type refinement because of shadowed variables"; [] end
else begin print_dbg dbg "Keeping type refinement"; [p2] end
in
p1 :: pl
in
let props = map param_to_props params in
List.Tot.flatten props
end
else
begin
print_dbg dbg "Ignoring the global parameters' types";
[]
end
end <: Tac (list term)
in
(* The global pre-condition is to be used only if none of its variables
* are shadowed (which implies that we are close enough to the top of
* the function *)
let gpre =
match ei.ei_pre, with_gpre with
| Some pre, true ->
if term_has_shadowed_variables ge1 pre then
begin
print_dbg dbg "Dropping the global precondition because of shadowed variables";
None
end
else ei.ei_pre
| _ -> None
in
(* The global post-condition and the type cast are relevant only if the
* studied term is not the definition in a let binding *)
let gpost, gcast_props =
if not with_gpost then None, []
else if is_let then
begin
print_dbg dbg "Dropping the global postcondition and return type because we are studying a let expression";
None, []
end
else
(* Because of the way the studied function is rewritten before being sent to F*
* we might have a problem with the return type (we might instantiate
* the return variable from the global post or from the return type
* refinement with a variable whose type is not valid for that, triggering
* an exception. In that case, we drop the post and the target type
* refinement. Note that here only the type refinement may be instantiated,
* we thus also need to check for the post inside ``pre_post_to_propositions`` *)
try
print_dbg dbg "> Generating propositions from the global type cast";
print_dbg dbg ("- known type: " ^ type_info_to_string einfo.ei_ret_type);
print_dbg dbg ("- exp. type : " ^ type_info_to_string ei.ei_ret_type);
let gcast = mk_cast_info v (Some einfo.ei_ret_type) (Some ei.ei_ret_type) in
print_dbg dbg (cast_info_to_string gcast);
let gcast_props = cast_info_to_propositions dbg ge1 gcast in
print_dbg dbg "> Propositions for global type cast:";
print_dbg dbg (list_to_string term_to_string gcast_props);
ei.ei_post, List.Tot.rev gcast_props
with
| _ ->
print_dbg dbg "Dropping the global postcondition and return type because of incoherent typing";
None, []
in
(* Generate the propositions from the precondition and the postcondition *)
(* TODO: not sure about the return type parameter: maybe catch failures *)
print_dbg dbg "> Instantiating global pre/post";
(* Note that we need to revert the lists of parents terms *)
(* For the children:
* - if the focused term is the return value and is pure: go look for
* a state variable introduced before
* - otherwise, use the children in revert order *)
let gchildren =
if is_let then rev children (* the postcondition should have been dropped anyway *)
else if effect_type_is_stateful einfo.ei_type then rev children
else parents
in
let ge2, gpre_prop, gpost_prop =
pre_post_to_propositions dbg ge1 ei.ei_type v opt_b einfo.ei_ret_type
gpre gpost (rev parents) gchildren in
(* Some debugging output *)
print_dbg dbg ("- global pre prop: " ^ option_to_string term_to_string gpre_prop);
print_dbg dbg ("- global post prop: " ^ option_to_string term_to_string gpost_prop);
(* Return type: *)
ge2, gparams_props, gpre_prop, gcast_props, gpost_prop
| _, _ ->
ge1, [], None, [], None
end <: Tac _
in
(* Generate the propositions: *)
(* - from the parameters' cast info *)
let params_props = cast_info_list_to_propositions dbg ge2 info.parameters in
(* - from the return type *)
let (ret_values : list term), (ret_binders : list binder) =
if E_Lemma? einfo.ei_type then ([] <: list term), ([] <: list binder)
else [v], (match opt_b with | Some b -> [b] | None -> []) in
let ret_has_type_prop =
match ret_values with
| [v] -> Some (mk_has_type v einfo.ei_ret_type.ty)
| _ -> None
in
let ret_refin_prop = opt_mk_app_norm ge2.env (get_opt_refinment einfo.ei_ret_type) ret_values in
(* Concatenate, revert and return *)
let pres = opt_cons gpre_prop (List.append params_props (opt_cons pre_prop [])) in
let pres = append gparams_props pres in
let posts = opt_cons ret_has_type_prop
(opt_cons ret_refin_prop (opt_cons post_prop
(List.append gcast_props (opt_cons gpost_prop [])))) in
(* Debugging output *)
print_dbg dbg "- generated pres:";
if dbg then iter (fun x -> print (term_to_string x)) pres;
print_dbg dbg "- generated posts:";
if dbg then iter (fun x -> print (term_to_string x)) posts;
ge2, { pres = pres; posts = posts }
end | val eterm_info_to_assertions :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> ge:genv
-> t:term
-> is_let:bool (* the term is the bound expression in a let binding *)
-> is_assert:bool (* the term is an assert - in which case we only output the precondition *)
-> info:eterm_info
-> opt_bind_var:option term (* if let binding: the bound var *)
-> opt_c:option typ_or_comp
-> parents:list term_view
-> children:list term_view ->
Tac (genv & assertions)
let eterm_info_to_assertions
dbg
with_gpre
with_gpost
ge
t
is_let
is_assert
info
bind_var
opt_c
parents
children
= | true | null | false | print_dbg dbg "[> eterm_info_to_assertions";
let einfo = info.einfo in
let ge0, (v: term), (opt_b: option binder) =
match bind_var with
| Some v -> ge, v, None
| None ->
if effect_type_is_stateful einfo.ei_type
then
if is_unit_type einfo.ei_ret_type.ty
then ge, (`()), None
else
let b = fresh_binder ge.env "__ret" einfo.ei_ret_type.ty in
let bv = bv_of_binder b in
let tm = pack (Tv_Var bv) in
genv_push_binder ge b true None, tm, Some b
else ge, t, None
in
print_dbg dbg "> Instantiating local pre/post";
let ge1, pre_prop, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type v opt_b einfo.ei_ret_type einfo.ei_pre
einfo.ei_post parents children
in
print_dbg dbg ("- pre prop: " ^ option_to_string term_to_string pre_prop);
print_dbg dbg ("- post prop: " ^ option_to_string term_to_string post_prop);
if is_assert
then
(print_dbg dbg "The term is an assert: only keep the postcondition";
ge1, { pres = opt_cons post_prop []; posts = [] })
else
let ge2, gparams_props, gpre_prop, gcast_props, gpost_prop =
let with_goal:bool = with_gpre || ((not is_let) && with_gpost) in
(match opt_c, with_goal with
| Some c, true ->
let ei = typ_or_comp_to_effect_info dbg ge1 c in
print_dbg dbg ("- target effect: " ^ effect_info_to_string ei);
print_dbg dbg ("- global unfilt. pre: " ^ option_to_string term_to_string ei.ei_pre);
print_dbg dbg ("- global unfilt. post: " ^ option_to_string term_to_string ei.ei_post);
let gparams_props =
(if with_gpre
then
(print_dbg dbg "Generating assertions from the global parameters' types";
print_dbg dbg ("Current genv:\n" ^ genv_to_string ge1);
let params =
rev (List.Tot.map (fun x -> (x, type_of_binder x)) (params_of_typ_or_comp c))
in
iteri (fun i (b, _) ->
print_dbg dbg
("Global parameter " ^ string_of_int i ^ ": " ^ binder_to_string b))
params;
let params = filter (fun (b, _) -> not (binder_is_shadowed ge1 b)) params in
let param_to_props (x: (binder & typ)) : Tac (list term) =
let b, ty = x in
let bv = bv_of_binder b in
print_dbg dbg
("Generating assertions from global parameter: " ^ binder_to_string b);
let tinfo = get_type_info_from_type ty in
let v = pack (Tv_Var bv) in
let p1 = mk_has_type v tinfo.ty in
let pl =
match tinfo.refin with
| None -> []
| Some r ->
let p2 = mk_app_norm ge1.env r [v] in
if term_has_shadowed_variables ge1 p2
then
(print_dbg dbg "Discarding type refinement because of shadowed variables";
[])
else
(print_dbg dbg "Keeping type refinement";
[p2])
in
p1 :: pl
in
let props = map param_to_props params in
List.Tot.flatten props)
else
(print_dbg dbg "Ignoring the global parameters' types";
[]))
<:
Tac (list term)
in
let gpre =
match ei.ei_pre, with_gpre with
| Some pre, true ->
if term_has_shadowed_variables ge1 pre
then
(print_dbg dbg "Dropping the global precondition because of shadowed variables";
None)
else ei.ei_pre
| _ -> None
in
let gpost, gcast_props =
if not with_gpost
then None, []
else
if is_let
then
(print_dbg dbg
"Dropping the global postcondition and return type because we are studying a let expression"
;
None, [])
else
try
(print_dbg dbg "> Generating propositions from the global type cast";
print_dbg dbg ("- known type: " ^ type_info_to_string einfo.ei_ret_type);
print_dbg dbg ("- exp. type : " ^ type_info_to_string ei.ei_ret_type);
let gcast = mk_cast_info v (Some einfo.ei_ret_type) (Some ei.ei_ret_type) in
print_dbg dbg (cast_info_to_string gcast);
let gcast_props = cast_info_to_propositions dbg ge1 gcast in
print_dbg dbg "> Propositions for global type cast:";
print_dbg dbg (list_to_string term_to_string gcast_props);
ei.ei_post, List.Tot.rev gcast_props)
with
| _ ->
print_dbg dbg
"Dropping the global postcondition and return type because of incoherent typing";
None, []
in
print_dbg dbg "> Instantiating global pre/post";
let gchildren =
if is_let
then rev children
else if effect_type_is_stateful einfo.ei_type then rev children else parents
in
let ge2, gpre_prop, gpost_prop =
pre_post_to_propositions dbg ge1 ei.ei_type v opt_b einfo.ei_ret_type gpre gpost
(rev parents) gchildren
in
print_dbg dbg ("- global pre prop: " ^ option_to_string term_to_string gpre_prop);
print_dbg dbg ("- global post prop: " ^ option_to_string term_to_string gpost_prop);
ge2, gparams_props, gpre_prop, gcast_props, gpost_prop
| _, _ -> ge1, [], None, [], None)
<:
Tac _
in
let params_props = cast_info_list_to_propositions dbg ge2 info.parameters in
let (ret_values: list term), (ret_binders: list binder) =
if E_Lemma? einfo.ei_type
then ([] <: list term), ([] <: list binder)
else
[v],
(match opt_b with
| Some b -> [b]
| None -> [])
in
let ret_has_type_prop =
match ret_values with
| [v] -> Some (mk_has_type v einfo.ei_ret_type.ty)
| _ -> None
in
let ret_refin_prop = opt_mk_app_norm ge2.env (get_opt_refinment einfo.ei_ret_type) ret_values in
let pres = opt_cons gpre_prop (List.append params_props (opt_cons pre_prop [])) in
let pres = append gparams_props pres in
let posts =
opt_cons ret_has_type_prop
(opt_cons ret_refin_prop
(opt_cons post_prop (List.append gcast_props (opt_cons gpost_prop []))))
in
print_dbg dbg "- generated pres:";
if dbg then iter (fun x -> print (term_to_string x)) pres;
print_dbg dbg "- generated posts:";
if dbg then iter (fun x -> print (term_to_string x)) posts;
ge2, { pres = pres; posts = posts } | {
"checked_file": "FStar.InteractiveHelpers.Effectful.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.Effectful.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Effectful.eterm_info",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"Prims.list",
"FStar.Reflection.V1.Data.term_view",
"FStar.Reflection.Types.binder",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.Propositions.assertions",
"FStar.InteractiveHelpers.Propositions.Mkassertions",
"FStar.InteractiveHelpers.Base.opt_cons",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.Tactics.Util.iter",
"FStar.Tactics.V1.Builtins.print",
"Prims.string",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.List.Tot.Base.append",
"FStar.InteractiveHelpers.Base.opt_mk_app_norm",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.InteractiveHelpers.Effectful.get_opt_refinment",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_ret_type",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.Effectful.mk_has_type",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__ty",
"FStar.Pervasives.Native.None",
"FStar.InteractiveHelpers.ExploreTerm.uu___is_E_Lemma",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_type",
"Prims.Cons",
"FStar.InteractiveHelpers.Effectful.cast_info_list_to_propositions",
"FStar.InteractiveHelpers.Effectful.__proj__Mketerm_info__item__parameters",
"FStar.Pervasives.Native.tuple5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Effectful.pre_post_to_propositions",
"FStar.List.Tot.Base.rev",
"FStar.InteractiveHelpers.Effectful.effect_type_is_stateful",
"Prims.op_Negation",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_post",
"FStar.InteractiveHelpers.Base.list_to_string",
"FStar.InteractiveHelpers.Effectful.cast_info_to_propositions",
"FStar.InteractiveHelpers.Effectful.cast_info_to_string",
"FStar.InteractiveHelpers.Effectful.cast_info",
"FStar.InteractiveHelpers.Effectful.mk_cast_info",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.type_info_to_string",
"Prims.exn",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_pre",
"FStar.InteractiveHelpers.ExploreTerm.term_has_shadowed_variables",
"FStar.List.Tot.Base.flatten",
"FStar.Tactics.Util.map",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.ExploreTerm.__proj__Mktype_info__item__refin",
"FStar.InteractiveHelpers.Base.mk_app_norm",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type",
"FStar.Tactics.V1.Derived.binder_to_string",
"FStar.Reflection.Types.bv",
"FStar.Reflection.V1.Derived.bv_of_binder",
"FStar.Tactics.Util.filter",
"FStar.InteractiveHelpers.Base.binder_is_shadowed",
"FStar.Tactics.Util.iteri",
"Prims.int",
"Prims.string_of_int",
"FStar.List.Tot.Base.map",
"FStar.Reflection.V1.Derived.type_of_binder",
"FStar.InteractiveHelpers.ExploreTerm.params_of_typ_or_comp",
"FStar.InteractiveHelpers.Base.genv_to_string",
"FStar.InteractiveHelpers.Effectful.effect_info_to_string",
"FStar.InteractiveHelpers.Effectful.effect_info",
"FStar.InteractiveHelpers.Effectful.typ_or_comp_to_effect_info",
"Prims.op_BarBar",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.Mktuple3",
"FStar.InteractiveHelpers.Base.genv_push_binder",
"FStar.InteractiveHelpers.Base.fresh_binder",
"FStar.InteractiveHelpers.ExploreTerm.is_unit_type",
"FStar.InteractiveHelpers.Effectful.__proj__Mketerm_info__item__einfo"
] | [] | module FStar.InteractiveHelpers.Effectful
module HS = FStar.HyperStack
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
let term_eq = FStar.Tactics.term_eq_old
/// Effectful term analysis: retrieve information about an effectful term, including
/// its return type, its arguments, its correctly instantiated pre/postcondition, etc.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** Effectful term analysis *)
/// Cast information
noeq type cast_info = {
term : term;
p_ty : option type_info; // The type of the term
exp_ty : option type_info; // The type of the expected parameter
}
let mk_cast_info t p_ty exp_ty : cast_info =
Mkcast_info t p_ty exp_ty
val cast_info_to_string : cast_info -> Tac string
let cast_info_to_string info =
"Mkcast_info (" ^ term_to_string info.term ^ ") (" ^
option_to_string type_info_to_string info.p_ty ^ ") (" ^
option_to_string type_info_to_string info.exp_ty ^ ")"
/// Extracts the effectful information from a computation
noeq type effect_info = {
ei_type : effect_type;
ei_ret_type : type_info;
ei_pre : option term;
ei_post : option term;
}
let mk_effect_info = Mkeffect_info
/// Convert a ``typ_or_comp`` to cast information
val effect_info_to_string : effect_info -> Tac string
let effect_info_to_string c =
"Mkeffect_info " ^
effect_type_to_string c.ei_type ^ " (" ^
option_to_string term_to_string c.ei_pre ^ ") (" ^
type_info_to_string c.ei_ret_type ^ ") (" ^
option_to_string term_to_string c.ei_post ^ ")"
/// Effectful term information
noeq type eterm_info = {
einfo : effect_info;
(* Head and parameters of the decomposition of the term into a function application *)
head : term;
parameters : list cast_info;
}
val eterm_info_to_string : eterm_info -> Tac string
let eterm_info_to_string info =
let params = map (fun x -> "(" ^ cast_info_to_string x ^ "); \n") info.parameters in
let params_str = List.Tot.fold_left (fun x y -> x ^ y) "" params in
"Mketerm_info (" ^
effect_info_to_string info.einfo ^ ") (" ^
term_to_string info.head ^ ")\n[" ^
params_str ^ "]"
let mk_eterm_info = Mketerm_info
(**** Step 1 *)
/// Decompose a function application between its body and parameters
val decompose_application : env -> term -> Tac (term & list cast_info)
#push-options "--ifuel 1"
let rec decompose_application_aux (e : env) (t : term) :
Tac (term & list cast_info) =
match inspect t with
| Tv_App hd (a, qualif) ->
let hd0, params = decompose_application_aux e hd in
(* Parameter type *)
let a_type = get_type_info e a in
(* Type expected by the function *)
let hd_ty = safe_tc e hd in
let param_type =
match hd_ty with
| None -> None
| Some hd_ty' ->
match inspect hd_ty' with
| Tv_Arrow b c ->
Some (get_type_info_from_type (binder_sort b))
| _ -> None
in
let cast_info = mk_cast_info a a_type param_type in
hd0, cast_info :: params
| _ -> t, []
#pop-options
let decompose_application e t =
let hd, params = decompose_application_aux e t in
hd, List.Tot.rev params
/// Computes an effect type, its return type and its (optional) pre and post
val comp_view_to_effect_info : dbg:bool -> comp_view -> Tac (option effect_info)
let comp_view_to_effect_info dbg cv =
match cv with
| C_Total ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_GTotal ret_ty ->
let ret_type_info = get_type_info_from_type ret_ty in
Some (mk_effect_info E_Total ret_type_info None None)
| C_Lemma pre post patterns ->
(* We use unit as the return type information *)
let pre = prettify_term dbg pre in
let post = prettify_term dbg post in
Some (mk_effect_info E_Lemma unit_type_info (Some pre) (Some post))
| C_Eff univs eff_name ret_ty eff_args _ ->
print_dbg dbg ("comp_view_to_effect_info: C_Eff " ^ flatten_name eff_name);
let ret_type_info = get_type_info_from_type ret_ty in
let etype = effect_name_to_type eff_name in
let mk_res = mk_effect_info etype ret_type_info in
let eff_args = map (fun (x,a) -> (prettify_term dbg x, a)) eff_args in
begin match etype, eff_args with
| E_PURE, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Pure, [(pre, _); (post, _)]
| E_Stack, [(pre, _); (post, _)]
| E_ST, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
(* If the effect is unknown and there are two parameters or less, we make the
* guess that the first one is a pre-condition and the second one is a
* post-condition *)
| E_Unknown, [] -> Some (mk_res None None)
| E_Unknown, [(pre, _)] -> Some (mk_res (Some pre) None)
| E_Unknown, [(pre, _); (post, _)] -> Some (mk_res (Some pre) (Some post))
| _ -> None
end
val comp_to_effect_info : dbg:bool -> comp -> Tac (option effect_info)
let comp_to_effect_info dbg c =
let cv : comp_view = inspect_comp c in
comp_view_to_effect_info dbg cv
val compute_effect_info : dbg:bool -> env -> term -> Tac (option effect_info)
let compute_effect_info dbg e tm =
match safe_tcc e tm with
| Some c -> comp_to_effect_info dbg c
| None -> None
/// Converts a ``typ_or_comp`` to an ``effect_info`` by flushing the instantiations
/// stored in the ``typ_or_comp``.
let typ_or_comp_to_effect_info (dbg : bool) (ge : genv) (c : typ_or_comp) :
Tac effect_info =
(* match c with
| TC_Typ ty pl num_unflushed ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv pl num_unflushed ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo *)
let c = flush_typ_or_comp dbg ge.env c in
match c with
| TC_Typ ty _ _ ->
let tinfo = get_type_info_from_type ty in
mk_effect_info E_Total tinfo None None
| TC_Comp cv _ _ ->
let opt_einfo = comp_to_effect_info dbg cv in
match opt_einfo with
| None -> mfail ("typ_or_comp_to_effect_info failed on: " ^ acomp_to_string cv)
| Some einfo -> einfo
/// ``tcc`` often returns a lifted effect which is not what we want (ex.: a
/// lemma called inside a Stack function may have been lifted to Stack, but
/// when studying this term effect, we want to retrieve its non-lifted effect).
/// The workaround is to decompose the term if it is an application, then retrieve
/// the effect of the head, and reconstruct it.
/// Note: I tried inspecting then repacking the term before calling ``tcc`` to
/// see if it allows to "forget" the context: it doesn't work.
val tcc_no_lift : env -> term -> Tac comp
let tcc_no_lift e t =
match inspect t with
| Tv_App _ _ ->
let hd, args = collect_app t in
let c = tcc e hd in
inst_comp e c (List.Tot.map fst args)
| _ ->
(* Fall back to ``tcc`` *)
tcc e t
/// Returns the effectful information about a term
val compute_eterm_info : dbg:bool -> env -> term -> Tac eterm_info
#push-options "--ifuel 2"
let compute_eterm_info (dbg : bool) (e : env) (t : term) =
(* Decompose the term if it is a function application *)
let hd, parameters = decompose_application e t in
try
begin
let c : comp = tcc_no_lift e t in
let opt_einfo = comp_to_effect_info dbg c in
match opt_einfo with
| None -> mfail ("compute_eterm_info: failed on: " ^ term_to_string t)
| Some einfo ->
mk_eterm_info einfo hd parameters
end
with
| TacticFailure msg ->
mfail ("compute_eterm_info: failure: '" ^ msg ^ "'")
| e -> raise e
#pop-options
(***** Types, casts and refinements *)
(* TODO: those are not needed anymore *)
let has_refinement (ty:type_info) : Tot bool =
Some? ty.refin
let get_refinement (ty:type_info{Some? ty.refin}) : Tot term =
Some?.v ty.refin
let get_opt_refinment (ty:type_info) : Tot (option term) =
ty.refin
let get_rawest_type (ty:type_info) : Tot typ =
ty.ty
/// Compare the type of a parameter and its expected type
type type_comparison = | Refines | Same_raw_type | Unknown
#push-options "--ifuel 1"
let type_comparison_to_string c =
match c with
| Refines -> "Refines"
| Same_raw_type -> "Same_raw_type"
| Unknown -> "Unknown"
#pop-options
// TODO: without debugging information generation, is Tot
let compare_types (dbg : bool) (info1 info2 : type_info) :
Tac (c:type_comparison{c = Same_raw_type ==> has_refinement info2}) =
print_dbg dbg "[> compare_types";
if term_eq info1.ty info2.ty then
let _ = print_dbg dbg "-> types are equal" in
if has_refinement info2 then
let _ = print_dbg dbg "-> 2nd type has refinement" in
// This doesn't work like in C: we need to check if info1 has a
// refinement, then we can compare the refinements inside ANOTHER if
if has_refinement info1 then
let _ = print_dbg dbg "-> 1st type has refinement" in
if term_eq (get_refinement info1) (get_refinement info2) then
let _ = print_dbg dbg "-> Refines" in
Refines
else
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 1st type has no refinement" in
let _ = print_dbg dbg "-> Same_raw_type" in
Same_raw_type // Same raw type but can't say anything about the expected refinement
else
let _ = print_dbg dbg "-> 2nd type has no refinement: Refines" in
Refines // The first type is more precise than the second type
else
let _ = print_dbg dbg "types are not equal" in
Unknown
let compare_cast_types (dbg : bool) (p:cast_info) :
Tac (c:type_comparison{
((c = Refines \/ c = Same_raw_type) ==> (Some? p.p_ty /\ Some? p.exp_ty)) /\
(c = Same_raw_type ==> has_refinement (Some?.v p.exp_ty))}) =
print_dbg dbg "[> compare_cast_types";
match p.p_ty, p.exp_ty with
| Some info1, Some info2 ->
compare_types dbg info1 info2
| _ -> Unknown
(*/// Retrieve the list of types from the parameters stored in ``typ_or_comp``.
val typ_or_comp_to_param_types : typ_or_comp -> Tot (list typ)
let typ_or_comp_to_param_types c =
let pl = params_of_typ_or_comp c in
List.Tot.map type_of_binder pl *)
(**** Step 2 *)
/// The retrieved type refinements and post-conditions are not instantiated (they
/// are lambda functions): instantiate them to get propositions.
/// Generate a term of the form [has_type x ty]
val mk_has_type : term -> typ -> Tac term
let mk_has_type t ty =
let params = [(ty, Q_Implicit); (t, Q_Explicit); (ty, Q_Explicit)] in
mk_app (`has_type) params
// TODO: I don't understand why I need ifuel 2 here
#push-options "--ifuel 2"
/// Generate the propositions equivalent to a correct type cast.
/// Note that the type refinements need to be instantiated.
val cast_info_to_propositions : bool -> genv -> cast_info -> Tac (list proposition)
let cast_info_to_propositions dbg ge ci =
print_dbg dbg ("[> cast_info_to_propositions:\n" ^ cast_info_to_string ci);
match compare_cast_types dbg ci with
| Refines ->
print_dbg dbg ("-> Comparison result: Refines");
[]
| Same_raw_type ->
print_dbg dbg ("-> Comparison result: Same_raw_type");
let refin = get_refinement (Some?.v ci.exp_ty) in
let inst_refin = mk_app_norm ge.env refin [ci.term] in
[inst_refin]
| Unknown ->
print_dbg dbg ("-> Comparison result: Unknown");
match ci.p_ty, ci.exp_ty with
| Some p_ty, Some e_ty ->
let p_rty = get_rawest_type p_ty in
let e_rty = get_rawest_type e_ty in
(* For the type cast, we generate an assertion of the form:
* [> has_type (p <: type_of_p) expected_type
* The reason is that we want the user to know which parameter is
* concerned (hence the ``has_type``), and which types should be
* related (hence the ascription).
*)
let ascr_term = pack (Tv_AscribedT ci.term p_rty None false) in
let has_type_params = [(p_rty, Q_Implicit); (ascr_term, Q_Explicit); (e_rty, Q_Explicit)] in
let type_cast = mk_app (`has_type) has_type_params in
(* Expected type's refinement *)
let inst_opt_refin = opt_mk_app_norm ge.env e_ty.refin [ci.term] in
opt_cons inst_opt_refin [type_cast]
| _ -> []
#pop-options
/// Generates a list of propositions from a list of ``cast_info``. Note that
/// the user should revert the list before printing the propositions.
val cast_info_list_to_propositions : bool -> genv -> list cast_info -> Tac (list proposition)
let cast_info_list_to_propositions dbg ge ls =
let lsl = map (cast_info_to_propositions dbg ge) ls in
flatten lsl
/// When dealing with unknown effects, we try to guess what the pre and post-conditions
/// are. The effects are indeed very likely to have a pre and a post-condition,
/// and to be parameterized with an internal effect state, so that the pre and posts
/// have the following shapes:
/// - pre : STATE -> Type0
/// - post : STATE -> RET -> STATE -> Type0
/// Or (no state/pure):
/// - pre : Type0
/// - post : RET -> Type0
/// We try to detect that with the following functions:
noeq type pre_post_type =
| PP_Unknown | PP_Pure
| PP_State : (state_type:term) -> pre_post_type
val compute_pre_type : bool -> env -> term -> Tac pre_post_type
let compute_pre_type dbg e pre =
print_dbg dbg "[> compute_pre_type";
match safe_tc e pre with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [], true ->
print_dbg dbg "PP_Pure";
PP_Pure
| [b], true ->
print_dbg dbg ("PP_State " ^ (term_to_string (type_of_binder b)));
PP_State (type_of_binder b)
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val opt_remove_refin : typ -> Tac typ
let opt_remove_refin ty =
match inspect ty with
| Tv_Refine _ sort _ -> sort
| _ -> ty
val compute_post_type : bool -> env -> term -> term -> Tac pre_post_type
let compute_post_type dbg e ret_type post =
print_dbg dbg "[> compute_post_type";
let get_tot_ret_type c : Tac (option term_view) =
match get_total_or_gtotal_ret_type c with
| Some ret_ty -> Some (inspect ret_ty)
| None -> None
in
match safe_tc e post with
| None ->
print_dbg dbg "safe_tc failed";
PP_Unknown
| Some ty ->
print_dbg dbg "safe_tc succeeded";
let brs, c = collect_arr_bs ty in
print_dbg dbg ("num binders: " ^ string_of_int (List.Tot.length brs));
match brs, is_total_or_gtotal c with
| [r], true ->
(* Pure *)
print_dbg dbg "PP_Pure";
PP_Pure
| [s1; r; s2], true ->
(* Stateful: check that the state types are coherent *)
let r_ty = type_of_binder r in
let s1_ty = type_of_binder s1 in
(* After testing with Stack: the final state seems to have a refinement
* (which gives the postcondition) so we need to remove it to match
* it against the initial state *)
let s2_ty = opt_remove_refin (type_of_binder s2) in
let ret_type_eq = term_eq ret_type r_ty in
let state_type_eq = term_eq s1_ty s2_ty in
print_dbg dbg ("- ret type:\n-- target: " ^ term_to_string ret_type ^
"\n-- binder: " ^ term_to_string r_ty);
print_dbg dbg ("- state types:\n-- binder1: " ^ term_to_string s1_ty ^
"\n-- binder2: " ^ term_to_string s2_ty);
print_dbg dbg ("- ret type equality: " ^ string_of_bool ret_type_eq);
print_dbg dbg ("- state types equality: " ^ string_of_bool state_type_eq);
if ret_type_eq && state_type_eq
then
begin
print_dbg dbg ("PP_State" ^ term_to_string (type_of_binder s1));
PP_State (type_of_binder s1)
end
else
begin
print_dbg dbg "PP_Unknown";
PP_Unknown
end
| _ ->
print_dbg dbg "PP_Unknown";
PP_Unknown
val check_pre_post_type : bool -> env -> term -> term -> term -> Tac pre_post_type
let check_pre_post_type dbg e pre ret_type post =
print_dbg dbg "[> check_pre_post_type";
match compute_pre_type dbg e pre, compute_post_type dbg e ret_type post with
| PP_Pure, PP_Pure ->
print_dbg dbg "PP_Pure, PP_Pure";
PP_Pure
| PP_State ty1, PP_State ty2 ->
print_dbg dbg "PP_State, PP_State";
if term_eq ty1 ty2 then PP_State ty1 else PP_Unknown
| _ ->
print_dbg dbg "_, _";
PP_Unknown
val check_opt_pre_post_type : bool -> env -> option term -> term -> option term -> Tac (option pre_post_type)
let check_opt_pre_post_type dbg e opt_pre ret_type opt_post =
print_dbg dbg "[> check_opt_pre_post_type";
match opt_pre, opt_post with
| Some pre, Some post ->
print_dbg dbg "Some pre, Some post";
Some (check_pre_post_type dbg e pre ret_type post)
| Some pre, None ->
print_dbg dbg "Some pre, None";
Some (compute_pre_type dbg e pre)
| None, Some post ->
print_dbg dbg "None, Some post";
Some (compute_post_type dbg e ret_type post)
| None, None ->
print_dbg dbg "None, None";
None
val _introduce_variables_for_abs : genv -> typ -> Tac (list term & list binder & genv)
let rec _introduce_variables_for_abs ge ty =
match inspect ty with
| Tv_Arrow b c ->
let ge1, b1 = genv_push_fresh_binder ge ("__" ^ name_of_binder b) (type_of_binder b) in
let bv1 = bv_of_binder b1 in
let v1 = pack (Tv_Var bv1) in
begin match get_total_or_gtotal_ret_type c with
| Some ty1 ->
let vl, bl, ge2 = _introduce_variables_for_abs ge1 ty1 in
v1 :: vl, b1 :: bl, ge2
| None -> [v1], [b1], ge1
end
| _ -> [], [], ge
val introduce_variables_for_abs : genv -> term -> Tac (list term & list binder & genv)
let introduce_variables_for_abs ge tm =
match safe_tc ge.env tm with
| Some ty -> _introduce_variables_for_abs ge ty
| None -> [], [], ge
val introduce_variables_for_opt_abs : genv -> option term -> Tac (list term & list binder & genv)
let introduce_variables_for_opt_abs ge opt_tm =
match opt_tm with
| Some tm -> introduce_variables_for_abs ge tm
| None -> [], [], ge
val effect_type_is_stateful : effect_type -> Tot bool
let effect_type_is_stateful etype =
match etype with
| E_Total | E_GTotal | E_Lemma | E_PURE | E_Pure -> false
| E_Stack | E_ST | E_Unknown -> true
let is_st_get dbg t : Tac bool =
print_dbg dbg ("[> is_st_get:\n" ^ term_to_string t);
match inspect t with
| Tv_App hd (a, qual) ->
print_dbg dbg "-> Is Tv_App";
begin match inspect hd with
| Tv_FVar fv ->
print_dbg dbg ("-> Head is Tv_FVar: " ^ fv_to_string fv);
fv_eq_name fv ["FStar"; "HyperStack"; "ST"; "get"]
| _ ->
print_dbg dbg "-> Head is not Tv_FVar";
false
end
| _ ->
print_dbg dbg "-> Is not Tv_App";
false
let is_let_st_get dbg (t : term_view) =
print_dbg dbg ("[> is_let_st_get:\n" ^ term_to_string t);
match t with
| Tv_Let recf attrs bv ty def body ->
print_dbg dbg "The term is a let expression";
if is_st_get dbg def then Some (bv, ty) else None
| _ ->
print_dbg dbg "The term is not a let expression";
None
// TODO: Define relation between parents and children in and use it in explore_term
// app: head or arg
// let : bv or def or child
// match: scrutinee or branch
// ascribed: e or ty
/// Check if a term's computation is effectful. The return type is option
/// because we may not be able to retrieve the term computation.
val term_has_effectful_comp : bool -> env -> term -> Tac (option bool)
let term_has_effectful_comp dbg e tm =
print_dbg dbg "[> term_has_effectful_comp";
let einfo_opt = compute_effect_info dbg e tm in
match einfo_opt with
| Some einfo ->
print_dbg dbg ("Effect type: " ^ effect_type_to_string einfo.ei_type);
Some (not (effect_type_is_pure einfo.ei_type))
| None ->
print_dbg dbg "Could not compute effect info";
None
/// Check if a related term is effectful. This is used to look for instances of
/// ``HS.mem`` to instantiate pre/postconditions, which means that the term should
/// be a parent/child term of the term under study, as generated by ``explore_term``
/// (otherwise the way we check that a term is effectful doesn't make sense).
/// The computation is an overapproximation: it may happen that, for instance, we
/// can't compute a term computation. In this case, we consider that the term is
/// effectful. There are also situations in which we may not be sure which term to
/// consider.
let related_term_is_effectul dbg ge tv : Tac bool =
let is_effectful tm =
term_has_effectful_comp dbg ge.env tm <> Some false
in
match tv with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> false
| Tv_App hd (a, qual) ->
(* The term under focus should be the app itself or an argument *)
false
| Tv_Abs br body -> false
| Tv_Arrow br c0 -> false
| Tv_Type _ -> false
| Tv_Refine bv sort ref ->
false
| Tv_Const _ -> false
| Tv_Uvar _ _ -> false
| Tv_Let recf attrs bv ty def body -> is_effectful def
| Tv_Match scrutinee _ret_opt branches ->
(* TODO: we need to keep track of the relation between parents and children *)
(* We assume the term under focus is in one the branches of the match - this
* assumption is safe: in the worst case, we won't be able to find a mem to use.
* Besides, in practice it is uncommon (impossible?) to use an effectful term
* as the scrutinee of a match *)
is_effectful scrutinee
| Tv_AscribedT e ty tac _ -> false (* The focused term should be inside the ascription *)
| Tv_AscribedC e c tac _ -> false (* The focused term should be inside the ascription *)
| _ -> (* Unknown: keep things safe *) true
/// Look for a term of the form ``let h = ST.get ()`` in a list of parent/children terms
/// and return the let-bound bv. Abort the search if we find a non-effectful term.
/// The typical usages of this function are the following:
/// - look for a state variable to instantiate the precondition of the term under focus
/// - look for state variables for the pre/postconditions of a term defined before
/// the term under focus.
val find_mem_in_related:
dbg:bool
-> ge:genv
-> tms:list term_view
-> Tac (option (bv & typ))
let rec find_mem_in_related dbg ge tms =
match tms with
| [] -> None
| tv :: tms' ->
print_dbg dbg ("[> find_mem_in_related:\n" ^ term_to_string tv);
match is_let_st_get dbg tv with
| Some bvt ->
print_dbg dbg "Term is of the form `let x = FStar.HyperStack.ST.get ()`: success";
Some bvt
| None ->
print_dbg dbg "Term is not of the form `let x = FStar.HyperStack.ST.get ()`: continuing";
if related_term_is_effectul dbg ge tv
then
begin
print_dbg dbg "Term is effectful: stopping here";
None
end
else
begin
print_dbg dbg "Term is not effectful: continuing";
find_mem_in_related dbg ge tms'
end
// TODO: not used for now
/// Look for a term of the form ``let h = ST.get ()`` in a child term (the
/// focused term is supposed to be a subterm of the definition of a let-construct).
val find_mem_in_children:
dbg:bool
-> ge:genv
-> child:term
-> Tac (genv & option bv)
let rec find_mem_in_children dbg ge child =
(* We stop whenever we find an expression which is not a let-binding *)
match inspect child with
| Tv_Let recf attrs bv ty def body ->
if is_st_get dbg def then ge, Some bv
else if term_has_effectful_comp dbg ge.env def <> Some false then ge, None
else
let ge1 = genv_push_bv ge bv ty false None in
find_mem_in_children dbg ge1 body
| _ -> ge, None
/// Instantiates optional pre and post conditions
val pre_post_to_propositions :
dbg:bool
-> ge:genv
-> etype:effect_type
-> ret_value:term
-> ret_abs_binder:option binder
-> ret_type:type_info
-> opt_pre:option term
-> opt_post:option term
-> parents:list term_view (* to look for state variables for the pre *)
-> children:list term_view (* to look for state variables for the pre and post *)
-> Tac (genv & option proposition & option proposition)
let pre_post_to_propositions dbg ge0 etype v ret_abs_binder ret_type opt_pre opt_post
parents children =
print_dbg dbg "[> pre_post_to_propositions: begin";
print_dbg dbg ("- uninstantiated pre: " ^ option_to_string term_to_string opt_pre);
print_dbg dbg ("- uninstantiated post: " ^ option_to_string term_to_string opt_post);
let brs = match ret_abs_binder with | None -> [] | Some b -> [b] in
(* Analyze the pre and the postcondition and introduce the necessary variables *)
let ge3, (pre_values, pre_binders), (post_values, post_binders) =
match etype with
| E_Lemma ->
print_dbg dbg "E_Lemma";
ge0, ([], []), ([(`())], [])
| E_Total | E_GTotal ->
print_dbg dbg "E_Total/E_GTotal";
ge0, ([], []), ([], [])
| E_PURE | E_Pure ->
print_dbg dbg "E_PURE/E_Pure";
ge0, ([], []), ([v], brs)
| E_Stack | E_ST ->
print_dbg dbg "E_Stack/E_ST";
(* Look for state variables in the context *)
print_dbg dbg "Looking for the initial state in the context";
let b1_opt = find_mem_in_related dbg ge0 parents in
print_dbg dbg "Looking for the final state in the context";
let b2_opt = find_mem_in_related dbg ge0 children in
(* Introduce state variables if necessary *)
let opt_push_fresh_state opt_bvt basename ge : Tac (term & binder & genv) =
match opt_bvt with
| Some (bv, ty) -> pack (Tv_Var bv), mk_binder bv ty, ge
| None -> genv_push_fresh_var ge basename (`HS.mem)
in
let h1, b1, ge1 = opt_push_fresh_state b1_opt "__h0_" ge0 in
let h2, b2, ge2 = opt_push_fresh_state b2_opt "__h1_" ge1 in
ge2, ([h1], [b1]), ([h1; v; h2], List.Tot.flatten ([b1]::brs::[[b2]]))
| E_Unknown ->
(* We don't know what the effect is and the current pre and post-conditions
* are currently guesses. Introduce any necessary variable abstracted by
* those parameters *)
(* The pre and post-conditions are likely to have the same shape as
* one of Pure or Stack (depending on whether we use or not an internal
* state). We try to check that and to instantiate them accordingly *)
let pp_type = check_opt_pre_post_type dbg ge0.env opt_pre ret_type.ty opt_post in
begin match pp_type with
| Some PP_Pure ->
print_dbg dbg "PP_Pure";
(* We only need the return value *)
ge0, ([], []), ([v], brs)
| Some (PP_State state_type) ->
print_dbg dbg "PP_State";
(* Introduce variables for the states *)
let s1, b1, s2, b2, ge1 = genv_push_two_fresh_vars ge0 "__s" state_type in
ge1, ([s1], [b1]), ([s1; v; s2], List.Tot.flatten ([b1]::brs::[[b2]]))
| Some PP_Unknown ->
print_dbg dbg "PP_Unknown";
(* Introduce variables for all the values, for the pre and the post *)
let pre_values, pre_binders, ge1 = introduce_variables_for_opt_abs ge0 opt_pre in
let post_values, post_binders, ge1 = introduce_variables_for_opt_abs ge1 opt_post in
ge1, (pre_values, pre_binders), (post_values, post_binders)
| _ ->
print_dbg dbg "No pre and no post";
(* No pre and no post *)
ge0, ([], []), ([], [])
end
in
(* Generate the propositions: *)
(* - from the precondition *)
let pre_prop = opt_mk_app_norm ge3.env opt_pre pre_values in
(* - from the postcondition - note that in the case of a global post-condition
* we might try to instantiate the return variable with a variable whose
* type is not correct, leading to an error. We thus catch errors below and
* drop the post if there is a problem *)
let post_prop =
try opt_mk_app_norm ge3.env opt_post post_values
with
| _ ->
print_dbg dbg "Dropping a postcondition because of incoherent typing";
None
in
(* return *)
print_dbg dbg "[> pre_post_to_propositions: end";
ge3, pre_prop, post_prop
/// Convert effectful type information to a list of propositions. May have to
/// introduce additional binders for the preconditions/postconditions/goal (hence
/// the environment in the return type).
/// The ``bind_var`` parameter is a variable if the studied term was bound in a let
/// expression.
val eterm_info_to_assertions :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> ge:genv
-> t:term
-> is_let:bool (* the term is the bound expression in a let binding *)
-> is_assert:bool (* the term is an assert - in which case we only output the precondition *)
-> info:eterm_info
-> opt_bind_var:option term (* if let binding: the bound var *)
-> opt_c:option typ_or_comp
-> parents:list term_view
-> children:list term_view ->
Tac (genv & assertions)
let eterm_info_to_assertions dbg with_gpre with_gpost ge t is_let is_assert info bind_var opt_c | false | false | FStar.InteractiveHelpers.Effectful.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eterm_info_to_assertions :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> ge:genv
-> t:term
-> is_let:bool (* the term is the bound expression in a let binding *)
-> is_assert:bool (* the term is an assert - in which case we only output the precondition *)
-> info:eterm_info
-> opt_bind_var:option term (* if let binding: the bound var *)
-> opt_c:option typ_or_comp
-> parents:list term_view
-> children:list term_view ->
Tac (genv & assertions) | [] | FStar.InteractiveHelpers.Effectful.eterm_info_to_assertions | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.Effectful.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
with_gpre: Prims.bool ->
with_gpost: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
t: FStar.Reflection.Types.term ->
is_let: Prims.bool ->
is_assert: Prims.bool ->
info: FStar.InteractiveHelpers.Effectful.eterm_info ->
opt_bind_var: FStar.Pervasives.Native.option FStar.Reflection.Types.term ->
opt_c: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp ->
parents: Prims.list FStar.Reflection.V1.Data.term_view ->
children: Prims.list FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.Base.genv * FStar.InteractiveHelpers.Propositions.assertions) | {
"end_col": 7,
"end_line": 962,
"start_col": 2,
"start_line": 766
} |
Prims.Tot | val view_n (t: base_typ) : pos | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let view_n (t:base_typ) : pos = view_n_unfold t | val view_n (t: base_typ) : pos
let view_n (t: base_typ) : pos = | false | null | false | view_n_unfold t | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Types.view_n_unfold",
"Prims.pos"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16 | false | true | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val view_n (t: base_typ) : pos | [] | Vale.Interop.Types.view_n | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Vale.Arch.HeapTypes_s.base_typ -> Prims.pos | {
"end_col": 47,
"end_line": 32,
"start_col": 32,
"start_line": 32
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_addr addr1 length1 addr2 length2 =
(* The first buffer is completely before the second, or the opposite *)
addr1 + length1 < addr2 ||
addr2 + length2 < addr1 | let disjoint_addr addr1 length1 addr2 length2 = | false | null | false | addr1 + length1 < addr2 || addr2 + length2 < addr1 | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.op_BarBar",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16
let view_n (t:base_typ) : pos = view_n_unfold t
[@__reduce__]
let down_view (t:base_typ) : DV.view (base_typ_as_type t) UInt8.t = match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128
let b8_preorder (writeable:bool) (a:Type0) : MB.srel a =
match writeable with
| true -> B.trivial_preorder a
| false -> IB.immutable_preorder a
[@__reduce__]
noeq
type b8 =
| Buffer:
#src:base_typ ->
writeable:bool ->
bsrc:MB.mbuffer (base_typ_as_type src)
(b8_preorder writeable (base_typ_as_type src))
(b8_preorder writeable (base_typ_as_type src)) ->
b8
let disjoint_addr addr1 length1 addr2 length2 = | false | true | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_addr : addr1: Prims.int -> length1: Prims.int -> addr2: Prims.int -> length2: Prims.int -> Prims.bool | [] | Vale.Interop.Types.disjoint_addr | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | addr1: Prims.int -> length1: Prims.int -> addr2: Prims.int -> length2: Prims.int -> Prims.bool | {
"end_col": 25,
"end_line": 61,
"start_col": 2,
"start_line": 60
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_downview
(#src:base_typ)
(#rrel #rel:MB.srel (base_typ_as_type src))
(b:MB.mbuffer (base_typ_as_type src) rrel rel) =
DV.mk_buffer_view b (down_view src) | let get_downview
(#src: base_typ)
(#rrel #rel: MB.srel (base_typ_as_type src))
(b: MB.mbuffer (base_typ_as_type src) rrel rel)
= | false | null | false | DV.mk_buffer_view b (down_view src) | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"sometrivial"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"LowStar.Monotonic.Buffer.srel",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.BufferView.Down.mk_buffer_view",
"FStar.UInt8.t",
"Vale.Interop.Types.down_view",
"LowStar.BufferView.Down.buffer"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16
let view_n (t:base_typ) : pos = view_n_unfold t
[@__reduce__]
let down_view (t:base_typ) : DV.view (base_typ_as_type t) UInt8.t = match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128
let b8_preorder (writeable:bool) (a:Type0) : MB.srel a =
match writeable with
| true -> B.trivial_preorder a
| false -> IB.immutable_preorder a
[@__reduce__]
noeq
type b8 =
| Buffer:
#src:base_typ ->
writeable:bool ->
bsrc:MB.mbuffer (base_typ_as_type src)
(b8_preorder writeable (base_typ_as_type src))
(b8_preorder writeable (base_typ_as_type src)) ->
b8
let disjoint_addr addr1 length1 addr2 length2 =
(* The first buffer is completely before the second, or the opposite *)
addr1 + length1 < addr2 ||
addr2 + length2 < addr1
let get_downview
(#src:base_typ)
(#rrel #rel:MB.srel (base_typ_as_type src)) | false | false | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_downview : b: LowStar.Monotonic.Buffer.mbuffer (Vale.Interop.Types.base_typ_as_type src) rrel rel
-> Prims.GTot (LowStar.BufferView.Down.buffer FStar.UInt8.t) | [] | Vale.Interop.Types.get_downview | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: LowStar.Monotonic.Buffer.mbuffer (Vale.Interop.Types.base_typ_as_type src) rrel rel
-> Prims.GTot (LowStar.BufferView.Down.buffer FStar.UInt8.t) | {
"end_col": 37,
"end_line": 67,
"start_col": 2,
"start_line": 67
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let addr_map_pred (m:b8 -> W.nat64) =
(forall (buf1 buf2:b8).{:pattern (m buf1); (m buf2)}
MB.disjoint buf1.bsrc buf2.bsrc ==>
disjoint_addr (m buf1) (DV.length (get_downview buf1.bsrc)) (m buf2) (DV.length (get_downview buf2.bsrc))) /\
(forall (b:b8).{:pattern (m b)} m b + DV.length (get_downview b.bsrc) < W.pow2_64) | let addr_map_pred (m: (b8 -> W.nat64)) = | false | null | false | (forall (buf1: b8) (buf2: b8). {:pattern (m buf1); (m buf2)}
MB.disjoint buf1.bsrc buf2.bsrc ==>
disjoint_addr (m buf1)
(DV.length (get_downview buf1.bsrc))
(m buf2)
(DV.length (get_downview buf2.bsrc))) /\
(forall (b: b8). {:pattern (m b)} m b + DV.length (get_downview b.bsrc) < W.pow2_64) | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Vale.Interop.Types.b8",
"Vale.Def.Words_s.nat64",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.disjoint",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.b2t",
"Vale.Interop.Types.disjoint_addr",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Prims.op_LessThan",
"Prims.op_Addition",
"Vale.Def.Words_s.pow2_64",
"Prims.logical"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16
let view_n (t:base_typ) : pos = view_n_unfold t
[@__reduce__]
let down_view (t:base_typ) : DV.view (base_typ_as_type t) UInt8.t = match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128
let b8_preorder (writeable:bool) (a:Type0) : MB.srel a =
match writeable with
| true -> B.trivial_preorder a
| false -> IB.immutable_preorder a
[@__reduce__]
noeq
type b8 =
| Buffer:
#src:base_typ ->
writeable:bool ->
bsrc:MB.mbuffer (base_typ_as_type src)
(b8_preorder writeable (base_typ_as_type src))
(b8_preorder writeable (base_typ_as_type src)) ->
b8
let disjoint_addr addr1 length1 addr2 length2 =
(* The first buffer is completely before the second, or the opposite *)
addr1 + length1 < addr2 ||
addr2 + length2 < addr1
let get_downview
(#src:base_typ)
(#rrel #rel:MB.srel (base_typ_as_type src))
(b:MB.mbuffer (base_typ_as_type src) rrel rel) =
DV.mk_buffer_view b (down_view src)
[@"opaque_to_smt"] | false | true | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val addr_map_pred : m: (_: Vale.Interop.Types.b8 -> Vale.Def.Words_s.nat64) -> Prims.logical | [] | Vale.Interop.Types.addr_map_pred | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: (_: Vale.Interop.Types.b8 -> Vale.Def.Words_s.nat64) -> Prims.logical | {
"end_col": 84,
"end_line": 74,
"start_col": 2,
"start_line": 71
} |
|
Prims.Tot | val b8_preorder (writeable: bool) (a: Type0) : MB.srel a | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let b8_preorder (writeable:bool) (a:Type0) : MB.srel a =
match writeable with
| true -> B.trivial_preorder a
| false -> IB.immutable_preorder a | val b8_preorder (writeable: bool) (a: Type0) : MB.srel a
let b8_preorder (writeable: bool) (a: Type0) : MB.srel a = | false | null | false | match writeable with
| true -> B.trivial_preorder a
| false -> IB.immutable_preorder a | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Prims.bool",
"LowStar.Buffer.trivial_preorder",
"LowStar.ImmutableBuffer.immutable_preorder",
"LowStar.Monotonic.Buffer.srel"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16
let view_n (t:base_typ) : pos = view_n_unfold t
[@__reduce__]
let down_view (t:base_typ) : DV.view (base_typ_as_type t) UInt8.t = match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128 | false | false | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val b8_preorder (writeable: bool) (a: Type0) : MB.srel a | [] | Vale.Interop.Types.b8_preorder | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | writeable: Prims.bool -> a: Type0 -> LowStar.Monotonic.Buffer.srel a | {
"end_col": 36,
"end_line": 45,
"start_col": 2,
"start_line": 43
} |
Prims.Tot | val base_typ_as_type (t: base_typ) : eqtype | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32 | val base_typ_as_type (t: base_typ) : eqtype
let base_typ_as_type (t: base_typ) : eqtype = | false | null | false | let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32 | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"FStar.UInt8.t",
"FStar.UInt16.t",
"FStar.UInt32.t",
"FStar.UInt64.t",
"Vale.Def.Types_s.quad32",
"Prims.eqtype"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__] | false | true | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val base_typ_as_type (t: base_typ) : eqtype | [] | Vale.Interop.Types.base_typ_as_type | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Vale.Arch.HeapTypes_s.base_typ -> Prims.eqtype | {
"end_col": 22,
"end_line": 20,
"start_col": 2,
"start_line": 13
} |
Prims.Tot | val view_n_unfold (t: base_typ) : pos | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16 | val view_n_unfold (t: base_typ) : pos
let view_n_unfold (t: base_typ) : pos = | false | null | false | match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16 | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.pos"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance | false | true | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val view_n_unfold (t: base_typ) : pos | [] | Vale.Interop.Types.view_n_unfold | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Vale.Arch.HeapTypes_s.base_typ -> Prims.pos | {
"end_col": 18,
"end_line": 30,
"start_col": 2,
"start_line": 25
} |
Prims.Tot | val down_view (t: base_typ) : DV.view (base_typ_as_type t) UInt8.t | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Vale.Def.Words_s",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let down_view (t:base_typ) : DV.view (base_typ_as_type t) UInt8.t = match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128 | val down_view (t: base_typ) : DV.view (base_typ_as_type t) UInt8.t
let down_view (t: base_typ) : DV.view (base_typ_as_type t) UInt8.t = | false | null | false | match t with
| TUInt8 -> Vale.Interop.Views.down_view8
| TUInt16 -> Vale.Interop.Views.down_view16
| TUInt32 -> Vale.Interop.Views.down_view32
| TUInt64 -> Vale.Interop.Views.down_view64
| TUInt128 -> Vale.Interop.Views.down_view128 | {
"checked_file": "Vale.Interop.Types.fst.checked",
"dependencies": [
"Vale.Interop.Views.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Types.fst"
} | [
"total"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Views.down_view8",
"Vale.Interop.Views.down_view16",
"Vale.Interop.Views.down_view32",
"Vale.Interop.Views.down_view64",
"Vale.Interop.Views.down_view128",
"LowStar.BufferView.Down.view",
"Vale.Interop.Types.base_typ_as_type",
"FStar.UInt8.t"
] | [] | module Vale.Interop.Types
open FStar.Mul
include Vale.Arch.HeapTypes_s
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module MB = LowStar.Monotonic.Buffer
module DV = LowStar.BufferView.Down
module W = Vale.Def.Words_s
module L = FStar.List.Tot
[@__reduce__]
let base_typ_as_type (t:base_typ) : eqtype =
let open W in
let open Vale.Def.Types_s in
match t with
| TUInt8 -> UInt8.t
| TUInt16 -> UInt16.t
| TUInt32 -> UInt32.t
| TUInt64 -> UInt64.t
| TUInt128 -> quad32
[@__reduce__]
unfold // without the unfold, "% view_n t" leads to very slow Z3 performance
let view_n_unfold (t:base_typ) : pos =
match t with
| TUInt8 -> 1
| TUInt16 -> 2
| TUInt32 -> 4
| TUInt64 -> 8
| TUInt128 -> 16
let view_n (t:base_typ) : pos = view_n_unfold t | false | false | Vale.Interop.Types.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val down_view (t: base_typ) : DV.view (base_typ_as_type t) UInt8.t | [] | Vale.Interop.Types.down_view | {
"file_name": "vale/specs/interop/Vale.Interop.Types.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Vale.Arch.HeapTypes_s.base_typ
-> LowStar.BufferView.Down.view (Vale.Interop.Types.base_typ_as_type t) FStar.UInt8.t | {
"end_col": 47,
"end_line": 40,
"start_col": 68,
"start_line": 35
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heaplet_id = M.heaplet_id | let heaplet_id = | false | null | false | M.heaplet_id | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Memory.heaplet_id"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val heaplet_id : Type0 | [] | Vale.X64.Decls.heaplet_id | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 36,
"end_line": 22,
"start_col": 24,
"start_line": 22
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vale_heap = M.vale_heap | let vale_heap = | false | null | false | M.vale_heap | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Memory.vale_heap"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vale_heap : Type | [] | Vale.X64.Decls.vale_heap | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type | {
"end_col": 34,
"end_line": 20,
"start_col": 23,
"start_line": 20
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b | let loc_buffer (#t: M.base_typ) (b: M.buffer t) = | false | null | false | M.loc_buffer #t b | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"sometrivial"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.loc_buffer",
"Vale.X64.Memory.loc"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h | false | false | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val loc_buffer : b: Vale.X64.Memory.buffer t -> Prims.GTot Vale.X64.Memory.loc | [] | Vale.X64.Decls.loc_buffer | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.X64.Memory.buffer t -> Prims.GTot Vale.X64.Memory.loc | {
"end_col": 71,
"end_line": 118,
"start_col": 54,
"start_line": 118
} |
|
Prims.Tot | val va_get_reg64 (r: reg_64) (s: va_state) : nat64 | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_get_reg64 (r:reg_64) (s:va_state) : nat64 = eval_reg_64 r s | val va_get_reg64 (r: reg_64) (s: va_state) : nat64
let va_get_reg64 (r: reg_64) (s: va_state) : nat64 = | false | null | false | eval_reg_64 r s | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Decls.va_state",
"Vale.X64.State.eval_reg_64",
"Vale.Def.Types_s.nat64"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index
let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index
let valid_mem_operand64 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer64) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr64 addr s_mem layout b index t
let valid_mem_operand128 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer128) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr128 addr s_mem layout b index t
[@va_qattr]
let valid_operand (o:operand64) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand o s /\
( match o with
| OMem (m, t) -> valid_mem_operand64 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack64 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
[@va_qattr]
let valid_operand128 (o:operand128) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand128 o s /\
( match o with
| OMem (m, t) -> valid_mem_operand128 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack128 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
(* Constructors *)
val va_fuel_default : unit -> va_fuel
[@va_qattr] unfold let va_op_xmm_xmm (x:reg_xmm) : va_operand_xmm = x
[@va_qattr] unfold let va_op_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_reg64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_opr128_xmm (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_const_opr64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_const_shift_amt64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_op_shift_amt64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_cmp_reg64 (r:reg_64) : cmp_operand = OReg r
[@va_qattr] unfold let va_const_cmp (n:nat64) : cmp_operand = OConst n
[@va_qattr] unfold let va_coerce_reg64_opr64_to_cmp (r:va_operand_reg_opr64) : cmp_operand = r
[@va_qattr] unfold let va_coerce_reg_opr64_to_dst_opr64 (o:va_operand_reg_opr64) : va_operand_dst_opr64 = o
[@va_qattr] unfold let va_coerce_reg_opr64_to_opr64 (o:va_operand_reg_opr64) : va_operand_opr64 = o
[@va_qattr] unfold let va_coerce_opr64_to_cmp (o:operand64{not (OMem? o)}) : cmp_operand = o
[@va_qattr] unfold let va_op_reg_opr64_reg64 (r:reg_64) : reg_operand = OReg r
[@va_qattr] unfold let va_op_dst_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_coerce_dst_opr64_to_opr64 (o:operand64) : operand64 = o
[@va_qattr] unfold let va_coerce_xmm_to_opr128 (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_op_heaplet_mem_heaplet (h:heaplet_id) : heaplet_id = h
[@va_qattr]
unfold let va_opr_code_Mem64 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OMem (MConst (n + offset), t)
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Stack (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OStack (MConst (n + offset), t)
| OReg r -> OStack (MReg (Reg 0 r) offset, t)
| _ -> OStack (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Mem128 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand128 =
match o with
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
val taint_at (memTaint:M.memtaint) (addr:int) : taint
(* Getters *)
[@va_qattr] unfold let va_get_ok (s:va_state) : bool = s.vs_ok | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_get_reg64 (r: reg_64) (s: va_state) : nat64 | [] | Vale.X64.Decls.va_get_reg64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | r: Vale.X64.Machine_s.reg_64 -> s: Vale.X64.Decls.va_state -> Vale.Def.Types_s.nat64 | {
"end_col": 85,
"end_line": 204,
"start_col": 70,
"start_line": 204
} |
Prims.Tot | val va_op_xmm_xmm (x: reg_xmm) : va_operand_xmm | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_op_xmm_xmm (x:reg_xmm) : va_operand_xmm = x | val va_op_xmm_xmm (x: reg_xmm) : va_operand_xmm
let va_op_xmm_xmm (x: reg_xmm) : va_operand_xmm = | false | null | false | x | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Decls.va_operand_xmm"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index
let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index
let valid_mem_operand64 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer64) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr64 addr s_mem layout b index t
let valid_mem_operand128 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer128) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr128 addr s_mem layout b index t
[@va_qattr]
let valid_operand (o:operand64) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand o s /\
( match o with
| OMem (m, t) -> valid_mem_operand64 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack64 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
[@va_qattr]
let valid_operand128 (o:operand128) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand128 o s /\
( match o with
| OMem (m, t) -> valid_mem_operand128 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack128 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
(* Constructors *) | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_op_xmm_xmm (x: reg_xmm) : va_operand_xmm | [] | Vale.X64.Decls.va_op_xmm_xmm | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.X64.Machine_s.reg_xmm -> Vale.X64.Decls.va_operand_xmm | {
"end_col": 69,
"end_line": 160,
"start_col": 68,
"start_line": 160
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_operand_opr64 = operand64 | let va_operand_opr64 = | false | null | false | operand64 | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_s.operand64"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_operand_opr64 : Prims.eqtype | [] | Vale.X64.Decls.va_operand_opr64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.eqtype | {
"end_col": 39,
"end_line": 73,
"start_col": 30,
"start_line": 73
} |
|
Prims.GTot | val buffer128_as_seq (m: vale_heap) (b: M.buffer128) : GTot (Seq.seq quad32) | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b | val buffer128_as_seq (m: vale_heap) (b: M.buffer128) : GTot (Seq.seq quad32)
let buffer128_as_seq (m: vale_heap) (b: M.buffer128) : GTot (Seq.seq quad32) = | false | null | false | M.buffer_as_seq m b | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"sometrivial"
] | [
"Vale.X64.Decls.vale_heap",
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Memory.vuint128",
"FStar.Seq.Base.seq",
"Vale.X64.Decls.quad32"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b | false | false | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer128_as_seq (m: vale_heap) (b: M.buffer128) : GTot (Seq.seq quad32) | [] | Vale.X64.Decls.buffer128_as_seq | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Vale.X64.Decls.vale_heap -> b: Vale.X64.Memory.buffer128
-> Prims.GTot (FStar.Seq.Base.seq Vale.X64.Decls.quad32) | {
"end_col": 103,
"end_line": 111,
"start_col": 84,
"start_line": 111
} |
Prims.Tot | val valid_buf_maddr128
(addr: int)
(s_mem: vale_heap)
(layout: vale_heap_layout)
(b: M.buffer128)
(index: int)
(t: taint)
: prop0 | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index | val valid_buf_maddr128
(addr: int)
(s_mem: vale_heap)
(layout: vale_heap_layout)
(b: M.buffer128)
(index: int)
(t: taint)
: prop0
let valid_buf_maddr128
(addr: int)
(s_mem: vale_heap)
(layout: vale_heap_layout)
(b: M.buffer128)
(index: int)
(t: taint)
: prop0 = | false | null | false | valid_src_addr s_mem b index /\ M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Prims.int",
"Vale.X64.Decls.vale_heap",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.X64.Memory.buffer128",
"Vale.Arch.HeapTypes_s.taint",
"Prims.l_and",
"Vale.X64.Decls.valid_src_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.valid_taint_buf128",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Prims.eq2",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"FStar.Mul.op_Star",
"Vale.Def.Prop_s.prop0"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_buf_maddr128
(addr: int)
(s_mem: vale_heap)
(layout: vale_heap_layout)
(b: M.buffer128)
(index: int)
(t: taint)
: prop0 | [] | Vale.X64.Decls.valid_buf_maddr128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
addr: Prims.int ->
s_mem: Vale.X64.Decls.vale_heap ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
b: Vale.X64.Memory.buffer128 ->
index: Prims.int ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.Def.Prop_s.prop0 | {
"end_col": 44,
"end_line": 130,
"start_col": 2,
"start_line": 128
} |
Prims.Tot | val va_coerce_reg_opr64_to_opr64 (o: va_operand_reg_opr64) : va_operand_opr64 | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_coerce_reg_opr64_to_opr64 (o:va_operand_reg_opr64) : va_operand_opr64 = o | val va_coerce_reg_opr64_to_opr64 (o: va_operand_reg_opr64) : va_operand_opr64
let va_coerce_reg_opr64_to_opr64 (o: va_operand_reg_opr64) : va_operand_opr64 = | false | null | false | o | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_operand_reg_opr64",
"Vale.X64.Decls.va_operand_opr64"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index
let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index
let valid_mem_operand64 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer64) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr64 addr s_mem layout b index t
let valid_mem_operand128 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer128) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr128 addr s_mem layout b index t
[@va_qattr]
let valid_operand (o:operand64) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand o s /\
( match o with
| OMem (m, t) -> valid_mem_operand64 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack64 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
[@va_qattr]
let valid_operand128 (o:operand128) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand128 o s /\
( match o with
| OMem (m, t) -> valid_mem_operand128 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack128 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
(* Constructors *)
val va_fuel_default : unit -> va_fuel
[@va_qattr] unfold let va_op_xmm_xmm (x:reg_xmm) : va_operand_xmm = x
[@va_qattr] unfold let va_op_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_reg64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_opr128_xmm (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_const_opr64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_const_shift_amt64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_op_shift_amt64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_cmp_reg64 (r:reg_64) : cmp_operand = OReg r
[@va_qattr] unfold let va_const_cmp (n:nat64) : cmp_operand = OConst n
[@va_qattr] unfold let va_coerce_reg64_opr64_to_cmp (r:va_operand_reg_opr64) : cmp_operand = r | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_coerce_reg_opr64_to_opr64 (o: va_operand_reg_opr64) : va_operand_opr64 | [] | Vale.X64.Decls.va_coerce_reg_opr64_to_opr64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | o: Vale.X64.Decls.va_operand_reg_opr64 -> Vale.X64.Decls.va_operand_opr64 | {
"end_col": 99,
"end_line": 171,
"start_col": 98,
"start_line": 171
} |
Prims.Tot | val va_subscript (#a: eqtype) (#b: Type) (x: Map.t a b) (y: a) : Tot b | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y | val va_subscript (#a: eqtype) (#b: Type) (x: Map.t a b) (y: a) : Tot b
let va_subscript (#a: eqtype) (#b: Type) (x: Map.t a b) (y: a) : Tot b = | false | null | false | Map.sel x y | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Prims.eqtype",
"FStar.Map.t",
"FStar.Map.sel"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags) | false | false | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_subscript (#a: eqtype) (#b: Type) (x: Map.t a b) (y: a) : Tot b | [] | Vale.X64.Decls.va_subscript | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: FStar.Map.t a b -> y: a -> b | {
"end_col": 87,
"end_line": 43,
"start_col": 76,
"start_line": 43
} |
Prims.Tot | val va_upd_ok (ok: bool) (s: vale_state) : vale_state | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_upd_ok (ok:bool) (s:vale_state) : vale_state = { s with vs_ok = ok } | val va_upd_ok (ok: bool) (s: vale_state) : vale_state
let va_upd_ok (ok: bool) (s: vale_state) : vale_state = | false | null | false | { s with vs_ok = ok } | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Prims.bool",
"Vale.X64.State.vale_state",
"Vale.X64.State.Mkvale_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.State.__proj__Mkvale_state__item__vs_flags",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index
let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index
let valid_mem_operand64 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer64) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr64 addr s_mem layout b index t
let valid_mem_operand128 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer128) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr128 addr s_mem layout b index t
[@va_qattr]
let valid_operand (o:operand64) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand o s /\
( match o with
| OMem (m, t) -> valid_mem_operand64 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack64 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
[@va_qattr]
let valid_operand128 (o:operand128) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand128 o s /\
( match o with
| OMem (m, t) -> valid_mem_operand128 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack128 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
(* Constructors *)
val va_fuel_default : unit -> va_fuel
[@va_qattr] unfold let va_op_xmm_xmm (x:reg_xmm) : va_operand_xmm = x
[@va_qattr] unfold let va_op_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_reg64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_opr128_xmm (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_const_opr64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_const_shift_amt64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_op_shift_amt64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_cmp_reg64 (r:reg_64) : cmp_operand = OReg r
[@va_qattr] unfold let va_const_cmp (n:nat64) : cmp_operand = OConst n
[@va_qattr] unfold let va_coerce_reg64_opr64_to_cmp (r:va_operand_reg_opr64) : cmp_operand = r
[@va_qattr] unfold let va_coerce_reg_opr64_to_dst_opr64 (o:va_operand_reg_opr64) : va_operand_dst_opr64 = o
[@va_qattr] unfold let va_coerce_reg_opr64_to_opr64 (o:va_operand_reg_opr64) : va_operand_opr64 = o
[@va_qattr] unfold let va_coerce_opr64_to_cmp (o:operand64{not (OMem? o)}) : cmp_operand = o
[@va_qattr] unfold let va_op_reg_opr64_reg64 (r:reg_64) : reg_operand = OReg r
[@va_qattr] unfold let va_op_dst_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_coerce_dst_opr64_to_opr64 (o:operand64) : operand64 = o
[@va_qattr] unfold let va_coerce_xmm_to_opr128 (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_op_heaplet_mem_heaplet (h:heaplet_id) : heaplet_id = h
[@va_qattr]
unfold let va_opr_code_Mem64 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OMem (MConst (n + offset), t)
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Stack (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OStack (MConst (n + offset), t)
| OReg r -> OStack (MReg (Reg 0 r) offset, t)
| _ -> OStack (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Mem128 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand128 =
match o with
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
val taint_at (memTaint:M.memtaint) (addr:int) : taint
(* Getters *)
[@va_qattr] unfold let va_get_ok (s:va_state) : bool = s.vs_ok
[@va_qattr] unfold let va_get_flags (s:va_state) : Flags.t = s.vs_flags
[@va_qattr] unfold let va_get_reg64 (r:reg_64) (s:va_state) : nat64 = eval_reg_64 r s
[@va_qattr] unfold let va_get_xmm (x:reg_xmm) (s:va_state) : quad32 = eval_reg_xmm x s
[@va_qattr] unfold let va_get_mem (s:va_state) : vale_heap = M.get_vale_heap s.vs_heap
[@va_qattr] unfold let va_get_mem_layout (s:va_state) : vale_heap_layout = s.vs_heap.vf_layout
[@va_qattr] unfold let va_get_mem_heaplet (n:heaplet_id) (s:va_state) : vale_heap = Map16.sel s.vs_heap.vf_heaplets n
[@va_qattr] unfold let va_get_stack (s:va_state) : S.vale_stack = s.vs_stack
[@va_qattr] unfold let va_get_stackTaint (s:va_state) : M.memtaint = s.vs_stackTaint | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_upd_ok (ok: bool) (s: vale_state) : vale_state | [] | Vale.X64.Decls.va_upd_ok | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ok: Prims.bool -> s: Vale.X64.State.vale_state -> Vale.X64.State.vale_state | {
"end_col": 85,
"end_line": 212,
"start_col": 68,
"start_line": 212
} |
Prims.Tot | val total_if (#a: Type) (b: bool) (x y: a) : a | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y | val total_if (#a: Type) (b: bool) (x y: a) : a
let total_if (#a: Type) (b: bool) (x y: a) : a = | false | null | false | if b then x else y | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Prims.bool"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y () | false | false | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val total_if (#a: Type) (b: bool) (x y: a) : a | [] | Vale.X64.Decls.total_if | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Prims.bool -> x: a -> y: a -> a | {
"end_col": 20,
"end_line": 57,
"start_col": 2,
"start_line": 57
} |
Prims.Tot | val va_get_mem (s: va_state) : vale_heap | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_get_mem (s:va_state) : vale_heap = M.get_vale_heap s.vs_heap | val va_get_mem (s: va_state) : vale_heap
let va_get_mem (s: va_state) : vale_heap = | false | null | false | M.get_vale_heap s.vs_heap | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_state",
"Vale.X64.Memory.get_vale_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.Decls.vale_heap"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0)
[@va_qattr] unfold let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y
[@va_qattr] unfold let va_expand_state (s:vale_state) : vale_state = state_eta s
unfold let get_reg (o:reg_operand) : reg = Reg 0 (OReg?.r o)
unfold let buffer_readable (#t:M.base_typ) (h:vale_heap) (b:M.buffer t) : GTot prop0 = M.buffer_readable #t h b
unfold let buffer_writeable (#t:M.base_typ) (b:M.buffer t) : GTot prop0 = M.buffer_writeable #t b
unfold let buffer_length (#t:M.base_typ) (b:M.buffer t) = M.buffer_length #t b
unfold let buffer8_as_seq (m:vale_heap) (b:M.buffer8) : GTot (Seq.seq nat8) = M.buffer_as_seq m b
unfold let buffer64_as_seq (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = M.buffer_as_seq m b
unfold let s64 (m:vale_heap) (b:M.buffer64) : GTot (Seq.seq nat64) = buffer64_as_seq m b
unfold let buffer128_as_seq (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = M.buffer_as_seq m b
unfold let s128 (m:vale_heap) (b:M.buffer128) : GTot (Seq.seq quad32) = buffer128_as_seq m b
unfold let valid_src_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_read m b i
unfold let valid_dst_addr (#t:M.base_typ) (m:vale_heap) (b:M.buffer t) (i:int) : prop0 = M.valid_buffer_write m b i
unfold let buffer64_read (b:M.buffer64) (i:int) (h:vale_heap) : GTot nat64 = M.buffer_read b i h
unfold let buffer128_read (b:M.buffer128) (i:int) (h:vale_heap) : GTot quad32 = M.buffer_read b i h
unfold let modifies_mem (s:M.loc) (h1 h2:vale_heap) : GTot prop0 = M.modifies s h1 h2
unfold let loc_buffer(#t:M.base_typ) (b:M.buffer t) = M.loc_buffer #t b
unfold let locs_disjoint = M.locs_disjoint
unfold let loc_union = M.loc_union
let valid_buf_maddr64 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer64) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf64 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 8 * index
let valid_buf_maddr128 (addr:int) (s_mem:vale_heap) (layout:vale_heap_layout) (b:M.buffer128) (index:int) (t:taint) : prop0 =
valid_src_addr s_mem b index /\
M.valid_taint_buf128 b s_mem layout.vl_taint t /\
addr == M.buffer_addr b s_mem + 16 * index
let valid_mem_operand64 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer64) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr64 addr s_mem layout b index t
let valid_mem_operand128 (addr:int) (t:taint) (s_mem:vale_heap) (layout:vale_heap_layout) : prop0 =
exists (b:M.buffer128) (index:int).{:pattern (M.valid_buffer_read s_mem b index)}
valid_buf_maddr128 addr s_mem layout b index t
[@va_qattr]
let valid_operand (o:operand64) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand o s /\
( match o with
| OMem (m, t) -> valid_mem_operand64 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack64 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
[@va_qattr]
let valid_operand128 (o:operand128) (s:vale_state) : prop0 =
Vale.X64.State.valid_src_operand128 o s /\
( match o with
| OMem (m, t) -> valid_mem_operand128 (eval_maddr m s) t (M.get_vale_heap s.vs_heap) s.vs_heap.vf_layout
| OStack (m, t) -> S.valid_taint_stack128 (eval_maddr m s) t s.vs_stackTaint
| _ -> True
)
(* Constructors *)
val va_fuel_default : unit -> va_fuel
[@va_qattr] unfold let va_op_xmm_xmm (x:reg_xmm) : va_operand_xmm = x
[@va_qattr] unfold let va_op_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_reg64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_opr128_xmm (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_const_opr64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_const_shift_amt64 (n:nat64) : operand64 = OConst n
[@va_qattr] unfold let va_op_shift_amt64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_op_cmp_reg64 (r:reg_64) : cmp_operand = OReg r
[@va_qattr] unfold let va_const_cmp (n:nat64) : cmp_operand = OConst n
[@va_qattr] unfold let va_coerce_reg64_opr64_to_cmp (r:va_operand_reg_opr64) : cmp_operand = r
[@va_qattr] unfold let va_coerce_reg_opr64_to_dst_opr64 (o:va_operand_reg_opr64) : va_operand_dst_opr64 = o
[@va_qattr] unfold let va_coerce_reg_opr64_to_opr64 (o:va_operand_reg_opr64) : va_operand_opr64 = o
[@va_qattr] unfold let va_coerce_opr64_to_cmp (o:operand64{not (OMem? o)}) : cmp_operand = o
[@va_qattr] unfold let va_op_reg_opr64_reg64 (r:reg_64) : reg_operand = OReg r
[@va_qattr] unfold let va_op_dst_opr64_reg64 (r:reg_64) : operand64 = OReg r
[@va_qattr] unfold let va_coerce_dst_opr64_to_opr64 (o:operand64) : operand64 = o
[@va_qattr] unfold let va_coerce_xmm_to_opr128 (x:reg_xmm) : operand128 = OReg x
[@va_qattr] unfold let va_op_heaplet_mem_heaplet (h:heaplet_id) : heaplet_id = h
[@va_qattr]
unfold let va_opr_code_Mem64 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OMem (MConst (n + offset), t)
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Stack (o:operand64) (offset:int) (t:taint) : operand64 =
match o with
| OConst n -> OStack (MConst (n + offset), t)
| OReg r -> OStack (MReg (Reg 0 r) offset, t)
| _ -> OStack (MConst 42, t)
[@va_qattr]
unfold let va_opr_code_Mem128 (h:heaplet_id) (o:operand64) (offset:int) (t:taint) : operand128 =
match o with
| OReg r -> OMem (MReg (Reg 0 r) offset, t)
| _ -> OMem (MConst 42, t)
val taint_at (memTaint:M.memtaint) (addr:int) : taint
(* Getters *)
[@va_qattr] unfold let va_get_ok (s:va_state) : bool = s.vs_ok
[@va_qattr] unfold let va_get_flags (s:va_state) : Flags.t = s.vs_flags
[@va_qattr] unfold let va_get_reg64 (r:reg_64) (s:va_state) : nat64 = eval_reg_64 r s | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_get_mem (s: va_state) : vale_heap | [] | Vale.X64.Decls.va_get_mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Vale.X64.Decls.va_state -> Vale.X64.Decls.vale_heap | {
"end_col": 86,
"end_line": 206,
"start_col": 61,
"start_line": 206
} |
Prims.Tot | val va_get_success (r: va_transformation_result) : va_pbool | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_get_success (r:va_transformation_result) : va_pbool = r.success | val va_get_success (r: va_transformation_result) : va_pbool
let va_get_success (r: va_transformation_result) : va_pbool = | false | null | false | r.success | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_transformation_result",
"Vale.X64.Decls.__proj__Mkva_transformation_result__item__success",
"Vale.X64.Decls.va_pbool"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code; | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_get_success (r: va_transformation_result) : va_pbool | [] | Vale.X64.Decls.va_get_success | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | r: Vale.X64.Decls.va_transformation_result -> Vale.X64.Decls.va_pbool | {
"end_col": 77,
"end_line": 94,
"start_col": 68,
"start_line": 94
} |
Prims.Tot | val va_mul_nat (x y: nat) : nat | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Print_s",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_mul_nat (x y:nat) : nat =
mul_nat_helper x y;
x * y | val va_mul_nat (x y: nat) : nat
let va_mul_nat (x y: nat) : nat = | false | null | false | mul_nat_helper x y;
x * y | {
"checked_file": "Vale.X64.Decls.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Decls.fsti"
} | [
"total"
] | [
"Prims.nat",
"FStar.Mul.op_Star",
"Prims.unit",
"Vale.X64.Decls.mul_nat_helper"
] | [] | module Vale.X64.Decls
open FStar.Mul
open Vale.Arch.HeapTypes_s
open Vale.Arch.HeapImpl
module M = Vale.X64.Memory
module S = Vale.X64.Stack_i
module Map16 = Vale.Lib.Map16
// This interface should hide all of Machine_Semantics_s.
// (It should not refer to Machine_Semantics_s, directly or indirectly.)
// It should not refer to StateLemmas, Lemmas, or Print_s,
// because they refer to Machine_Semantics_s.
// Stack_i, Memory, Regs, Flags and State are ok, because they do not refer to Machine_Semantics_s.
open Vale.Def.Prop_s
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.Def.Types_s
unfold let vale_heap = M.vale_heap
unfold let vale_full_heap = M.vale_full_heap
unfold let heaplet_id = M.heaplet_id
unfold let quad32 = quad32
val cf (flags:Flags.t) : bool
val overflow (flags:Flags.t) : bool
val valid_cf (flags:Flags.t) : bool
val valid_of (flags:Flags.t) : bool
val updated_cf (new_flags:Flags.t) (new_cf:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == new_cf /\ valid_cf new_flags)
val updated_of (new_flags:Flags.t) (new_of:bool) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == new_of /\ valid_of new_flags)
val maintained_cf (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> cf new_flags == cf flags /\ valid_cf new_flags == valid_cf flags)
val maintained_of (new_flags:Flags.t) (flags:Flags.t) : Pure bool
(requires True)
(ensures fun b -> b <==> overflow new_flags == overflow flags /\ valid_of new_flags == valid_of flags)
//unfold let va_subscript = Map.sel
unfold let va_subscript (#a:eqtype) (#b:Type) (x:Map.t a b) (y:a) : Tot b = Map.sel x y
unfold let va_update = Map.upd
unfold let va_hd = Cons?.hd
//unfold let va_tl = Cons?.tl // F* inlines "let ... = va_tl ..." more than we'd like; revised definition below suppresses this
// REVIEW: reveal_opaque doesn't include zeta, so it fails for recursive functions
[@va_qattr] unfold let va_reveal_eq (#ax:Type) (s:string) (x x':ax) = norm [zeta; delta_only [s]] #ax x == x'
let va_reveal_opaque (s:string) = norm_spec [zeta; delta_only [s]]
// hide 'if' so that x and y get fully normalized
let va_if (#a:Type) (b:bool) (x:(_:unit{b}) -> GTot a) (y:(_:unit{~b}) -> GTot a) : GTot a =
if b then x () else y ()
let total_if (#a:Type) (b:bool) (x y:a) : a =
if b then x else y
let total_thunk_if (#a:Type) (b:bool) (x:(_:unit{b}) -> a) (y:(_:unit{~b}) -> a) : a =
if b then x () else y ()
(* Type aliases *)
let va_int_at_least (k:int) = i:int{i >= k}
let va_int_at_most (k:int) = i:int{i <= k}
let va_int_range (k1 k2:int) = i:int{k1 <= i /\ i <= k2}
val ins : Type0
val ocmp : eqtype
unfold let va_code = precode ins ocmp
unfold let va_codes = list va_code
let va_tl (cs:va_codes) : Ghost va_codes (requires Cons? cs) (ensures fun tl -> tl == Cons?.tl cs) = Cons?.tl cs
unfold let va_state = vale_state
val va_fuel : Type0
unfold let va_operand_opr64 = operand64
let reg_operand = o:operand64{OReg? o}
let va_operand_reg_opr64 = o:operand64{OReg? o}
unfold let va_operand_dst_opr64 = operand64
unfold let va_operand_shift_amt64 = operand64
unfold let cmp_operand = o:operand64{not (OMem? o)}
unfold let va_operand_xmm = reg_xmm
unfold let va_operand_opr128 = operand128
unfold let va_operand_heaplet = heaplet_id
val va_pbool : Type0
val va_ttrue (_:unit) : va_pbool
val va_ffalse (reason:string) : va_pbool
val va_pbool_and (x y:va_pbool) : va_pbool
val get_reason (p:va_pbool) : option string
noeq
type va_transformation_result = {
success : va_pbool;
result : va_code;
}
unfold let va_get_success (r:va_transformation_result) : va_pbool = r.success
unfold let va_get_result (r:va_transformation_result) : va_code = r.result
val mul_nat_helper (x y:nat) : Lemma (x * y >= 0) | false | true | Vale.X64.Decls.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_mul_nat (x y: nat) : nat | [] | Vale.X64.Decls.va_mul_nat | {
"file_name": "vale/code/arch/x64/Vale.X64.Decls.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.nat -> y: Prims.nat -> Prims.nat | {
"end_col": 7,
"end_line": 100,
"start_col": 2,
"start_line": 99
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.