file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HyE.HCCA2.fst | HyE.HCCA2.keygen | val keygen: parent:C.rid{HyperStack.ST.witnessed (region_contains_pred parent)} -> ML (pkey * skey) | val keygen: parent:C.rid{HyperStack.ST.witnessed (region_contains_pred parent)} -> ML (pkey * skey) | let keygen parent =
let cca_pk, cca_sk = C.keygen parent in
let region = new_region parent in
let pkey = PKey #region (C.access_pk_raw cca_pk) cca_pk in
pkey, SKey cca_sk pkey | {
"file_name": "examples/crypto/HyE.HCCA2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 46,
"start_col": 0,
"start_line": 42
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HyE.HCCA2
open FStar.HyperStack.All
open FStar.HyperStack.ST
open HyE.Plain
open HyE.PlainPKE
open Platform.Bytes
open FStar.HyperStack
module B = Platform.Bytes
module P = HyE.Plain
module C = HyE.CCA2
module A = HyE.AE
module RSA = HyE.RSA
(* we idealize first CCA2, then AE *)
noeq type pkey =
| PKey: #region:C.rid{HyperStack.ST.witnessed (region_contains_pred region)} -> rawpk:RSA.pkey -> cca_pk:C.pkey -> pkey
let access_pkraw (pk:pkey) =
PKey?.rawpk pk
noeq type skey =
| SKey: cca_sk:C.skey -> pk:pkey -> skey | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Platform.Bytes.fst.checked",
"HyE.RSA.fst.checked",
"HyE.PlainPKE.fst.checked",
"HyE.Plain.fsti.checked",
"HyE.CCA2.fsti.checked",
"HyE.AE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "HyE.HCCA2.fst"
} | [
{
"abbrev": true,
"full_module": "HyE.RSA",
"short_module": "RSA"
},
{
"abbrev": true,
"full_module": "HyE.AE",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "HyE.CCA2",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "HyE.Plain",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Platform.Bytes",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Platform.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE.PlainPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE.Plain",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
parent:
HyE.CCA2.rid{FStar.HyperStack.ST.witnessed (FStar.HyperStack.ST.region_contains_pred parent)}
-> FStar.HyperStack.All.ML (HyE.HCCA2.pkey * HyE.HCCA2.skey) | FStar.HyperStack.All.ML | [] | [] | [
"HyE.CCA2.rid",
"FStar.HyperStack.ST.witnessed",
"FStar.HyperStack.ST.region_contains_pred",
"HyE.CCA2.pkey",
"HyE.CCA2.skey",
"FStar.Pervasives.Native.Mktuple2",
"HyE.HCCA2.pkey",
"HyE.HCCA2.skey",
"HyE.HCCA2.SKey",
"HyE.HCCA2.PKey",
"HyE.CCA2.access_pk_raw",
"FStar.Pervasives.Native.tuple2",
"FStar.Monotonic.HyperHeap.rid",
"FStar.HyperStack.ST.new_region",
"HyE.CCA2.keygen"
] | [] | false | true | false | false | false | let keygen parent =
| let cca_pk, cca_sk = C.keygen parent in
let region = new_region parent in
let pkey = PKey #region (C.access_pk_raw cca_pk) cca_pk in
pkey, SKey cca_sk pkey | false |
HyE.HCCA2.fst | HyE.HCCA2.encrypt | val encrypt: pkey -> p -> ML c | val encrypt: pkey -> p -> ML c | let encrypt pk t =
let region = new_region pk.region in
let k = A.keygen region in
((C.encrypt pk.cca_pk k) ,(A.encrypt k t)) | {
"file_name": "examples/crypto/HyE.HCCA2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 51,
"start_col": 0,
"start_line": 48
} | (*
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 HyE.HCCA2
open FStar.HyperStack.All
open FStar.HyperStack.ST
open HyE.Plain
open HyE.PlainPKE
open Platform.Bytes
open FStar.HyperStack
module B = Platform.Bytes
module P = HyE.Plain
module C = HyE.CCA2
module A = HyE.AE
module RSA = HyE.RSA
(* we idealize first CCA2, then AE *)
noeq type pkey =
| PKey: #region:C.rid{HyperStack.ST.witnessed (region_contains_pred region)} -> rawpk:RSA.pkey -> cca_pk:C.pkey -> pkey
let access_pkraw (pk:pkey) =
PKey?.rawpk pk
noeq type skey =
| SKey: cca_sk:C.skey -> pk:pkey -> skey
let keygen parent =
let cca_pk, cca_sk = C.keygen parent in
let region = new_region parent in
let pkey = PKey #region (C.access_pk_raw cca_pk) cca_pk in
pkey, SKey cca_sk pkey | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Platform.Bytes.fst.checked",
"HyE.RSA.fst.checked",
"HyE.PlainPKE.fst.checked",
"HyE.Plain.fsti.checked",
"HyE.CCA2.fsti.checked",
"HyE.AE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "HyE.HCCA2.fst"
} | [
{
"abbrev": true,
"full_module": "HyE.RSA",
"short_module": "RSA"
},
{
"abbrev": true,
"full_module": "HyE.AE",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "HyE.CCA2",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "HyE.Plain",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Platform.Bytes",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Platform.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE.PlainPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE.Plain",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE",
"short_module": null
},
{
"abbrev": false,
"full_module": "HyE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pk: HyE.HCCA2.pkey -> t: HyE.HCCA2.p -> FStar.HyperStack.All.ML HyE.HCCA2.c | FStar.HyperStack.All.ML | [] | [] | [
"HyE.HCCA2.pkey",
"HyE.HCCA2.p",
"FStar.Pervasives.Native.Mktuple2",
"HyE.CCA2.cipher",
"HyE.AE.cipher",
"HyE.HCCA2.c",
"HyE.AE.encrypt",
"HyE.CCA2.encrypt",
"HyE.HCCA2.__proj__PKey__item__cca_pk",
"HyE.RSA.cipher",
"HyE.AE.key",
"HyE.AE.keygen",
"FStar.Monotonic.HyperHeap.rid",
"FStar.HyperStack.ST.new_region",
"HyE.HCCA2.__proj__PKey__item__region"
] | [] | false | true | false | false | false | let encrypt pk t =
| let region = new_region pk.region in
let k = A.keygen region in
((C.encrypt pk.cca_pk k), (A.encrypt k t)) | false |
GlobalEnv.fst | GlobalEnv.default_probe_fn | val default_probe_fn (g: global_env) : ML (option ident) | val default_probe_fn (g: global_env) : ML (option ident) | let default_probe_fn (g:global_env)
: ML (option ident)
= if H.length g.ge_probe_fn <> 1
then None
else (
match H.fold (fun k v _ -> Some v) g.ge_probe_fn (None #decl) with
| Some {d_decl={v=ExternProbe id}} -> Some id
| _ -> None
) | {
"file_name": "src/3d/GlobalEnv.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 91,
"start_col": 0,
"start_line": 83
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module GlobalEnv
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
/// Computed attributes for a decl:
/// -- its size in bytes
/// -- whether or not it ends with a variable-length field (suffix)
/// -- whether or not its validator may fail
/// -- whether the type is an integral type, i.e., can it be decomposed into bitfields
type decl_attributes = {
may_fail:bool;
integral:option integer_type;
bit_order: (bit_order: option bitfield_bit_order { Some? bit_order ==> Some? integral });
has_reader:bool;
parser_weak_kind:weak_kind;
parser_kind_nz:option bool
}
noeq
type macro_signature = {
macro_arguments_t: list typ;
macro_result_t: typ;
macro_defn_t:option expr
}
let nullary_macro t d = {
macro_arguments_t = [];
macro_result_t = t;
macro_defn_t = d
}
(* Type-checking environments *)
/// global_env ge_h field is a hash (hence `_h`) table that:
/// -- maps top-level identifiers to their corresponding declaration
/// -- maps type identifiers to decl_attributes
/// -- maps macro names to their types
///
/// global_env ge_fd field maps a unique numerical identifier to each
/// "struct identifier - field (hence `_fd`) name" pair. It is part of
/// the global environment so that numerical field identifiers are
/// proper to the current module, and not shared across different .3d
/// files given on the command line
type global_hash_t = H.t ident' (decl & either decl_attributes macro_signature)
noeq
type global_env = {
ge_h: global_hash_t;
ge_out_t: H.t ident' decl; //a table for output types declarations
ge_extern_t: H.t ident' decl; //a table for extern type declarations
ge_extern_fn: H.t ident' decl; //a table for extern function declarations
ge_probe_fn: H.t ident' decl; //a table for probe function declarations
ge_cfg: option (Config.config & string)
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.All.fst.checked",
"Config.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "GlobalEnv.fst"
} | [
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: GlobalEnv.global_env -> FStar.All.ML (FStar.Pervasives.Native.option Ast.ident) | FStar.All.ML | [
"ml"
] | [] | [
"GlobalEnv.global_env",
"FStar.Pervasives.Native.None",
"Ast.ident",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Ast.range",
"Ast.comments",
"FStar.Pervasives.Native.Some",
"Ast.decl",
"Hashtable.fold",
"Ast.ident'",
"GlobalEnv.__proj__Mkglobal_env__item__ge_probe_fn",
"Prims.op_disEquality",
"Prims.int",
"Hashtable.length"
] | [] | false | true | false | false | false | let default_probe_fn (g: global_env) : ML (option ident) =
| if H.length g.ge_probe_fn <> 1
then None
else
(match H.fold (fun k v _ -> Some v) g.ge_probe_fn (None #decl) with
| Some { d_decl = { v = ExternProbe id } } -> Some id
| _ -> None) | false |
GlobalEnv.fst | GlobalEnv.resolve_probe_fn | val resolve_probe_fn (g: global_env) (id: ident) : ML (option ident) | val resolve_probe_fn (g: global_env) (id: ident) : ML (option ident) | let resolve_probe_fn (g:global_env) (id:ident)
: ML (option ident)
= match H.try_find g.ge_probe_fn id.v with
| Some {d_decl={v=ExternProbe id}} -> Some id
| _ -> None | {
"file_name": "src/3d/GlobalEnv.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 97,
"start_col": 0,
"start_line": 93
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain as copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module GlobalEnv
(*
This module implements a pass over the source AST
-- checking that all names are properly bound
-- well-typed
-- computing the size of types
-- computing which fields are dependent on others
*)
open FStar.Mul
open FStar.List.Tot
open Ast
open FStar.All
module H = Hashtable
/// Computed attributes for a decl:
/// -- its size in bytes
/// -- whether or not it ends with a variable-length field (suffix)
/// -- whether or not its validator may fail
/// -- whether the type is an integral type, i.e., can it be decomposed into bitfields
type decl_attributes = {
may_fail:bool;
integral:option integer_type;
bit_order: (bit_order: option bitfield_bit_order { Some? bit_order ==> Some? integral });
has_reader:bool;
parser_weak_kind:weak_kind;
parser_kind_nz:option bool
}
noeq
type macro_signature = {
macro_arguments_t: list typ;
macro_result_t: typ;
macro_defn_t:option expr
}
let nullary_macro t d = {
macro_arguments_t = [];
macro_result_t = t;
macro_defn_t = d
}
(* Type-checking environments *)
/// global_env ge_h field is a hash (hence `_h`) table that:
/// -- maps top-level identifiers to their corresponding declaration
/// -- maps type identifiers to decl_attributes
/// -- maps macro names to their types
///
/// global_env ge_fd field maps a unique numerical identifier to each
/// "struct identifier - field (hence `_fd`) name" pair. It is part of
/// the global environment so that numerical field identifiers are
/// proper to the current module, and not shared across different .3d
/// files given on the command line
type global_hash_t = H.t ident' (decl & either decl_attributes macro_signature)
noeq
type global_env = {
ge_h: global_hash_t;
ge_out_t: H.t ident' decl; //a table for output types declarations
ge_extern_t: H.t ident' decl; //a table for extern type declarations
ge_extern_fn: H.t ident' decl; //a table for extern function declarations
ge_probe_fn: H.t ident' decl; //a table for probe function declarations
ge_cfg: option (Config.config & string)
}
let default_probe_fn (g:global_env)
: ML (option ident)
= if H.length g.ge_probe_fn <> 1
then None
else (
match H.fold (fun k v _ -> Some v) g.ge_probe_fn (None #decl) with
| Some {d_decl={v=ExternProbe id}} -> Some id
| _ -> None
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.All.fst.checked",
"Config.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "GlobalEnv.fst"
} | [
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: GlobalEnv.global_env -> id: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option Ast.ident) | FStar.All.ML | [
"ml"
] | [] | [
"GlobalEnv.global_env",
"Ast.ident",
"Ast.range",
"Ast.comments",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"Ast.decl",
"FStar.Pervasives.Native.None",
"Hashtable.try_find",
"Ast.ident'",
"GlobalEnv.__proj__Mkglobal_env__item__ge_probe_fn",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [] | false | true | false | false | false | let resolve_probe_fn (g: global_env) (id: ident) : ML (option ident) =
| match H.try_find g.ge_probe_fn id.v with
| Some { d_decl = { v = ExternProbe id } } -> Some id
| _ -> None | false |
Steel.ST.CancellableSpinLock.fsti | Steel.ST.CancellableSpinLock.maybe_acquired | val maybe_acquired : b: Prims.bool -> c: Steel.ST.CancellableSpinLock.cancellable_lock v -> Steel.Effect.Common.vprop | let maybe_acquired (b:bool) (#v:vprop) (c:cancellable_lock v)
= if b then (v `star` can_release c) else emp | {
"file_name": "lib/steel/Steel.ST.CancellableSpinLock.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 52,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT 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: Aseem Rastogi
*)
module Steel.ST.CancellableSpinLock
open Steel.ST.Effect
/// This module provides a cancellable spinlock Steel library
///
/// As with Steel.ST.SpinLock, a cancellable spinlock guards
/// a separation logic assertion
///
/// However, it allows for the cases when the client is not able
/// to maintain the assertion
///
/// At that point, the client may just cancel the lock
/// The lock type that guards the assertion `v`
val cancellable_lock (v:vprop) : Type0
/// A cancellable lock can be created by providing `v`
val new_cancellable_lock (v:vprop)
: STT (cancellable_lock v) v (fun _ -> emp)
/// `can_release` is the permission to release the lock
///
/// Acquiring the lock, if it succeeds, provides `v`, the protected assertion
/// and `can_release`
val can_release (#v:vprop) (c:cancellable_lock v) : vprop | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.CancellableSpinLock.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Prims.bool -> c: Steel.ST.CancellableSpinLock.cancellable_lock v -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Steel.Effect.Common.vprop",
"Steel.ST.CancellableSpinLock.cancellable_lock",
"Steel.Effect.Common.star",
"Steel.ST.CancellableSpinLock.can_release",
"Steel.Effect.Common.emp"
] | [] | false | false | false | false | false | let maybe_acquired (b: bool) (#v: vprop) (c: cancellable_lock v) =
| if b then (v `star` (can_release c)) else emp | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.lookup_fvar | val lookup_fvar (e: env) (x: fv) : option term | val lookup_fvar (e: env) (x: fv) : option term | let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 126,
"start_col": 0,
"start_line": 126
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.env -> x: FStar.Stubs.Reflection.Types.fv
-> FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Reflection.Typing.lookup_fvar_uinst",
"Prims.Nil",
"FStar.Stubs.Reflection.Types.universe",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let lookup_fvar (e: env) (x: fv) : option term =
| lookup_fvar_uinst e x [] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.pp_name_default | val pp_name_default:pp_name_t | val pp_name_default:pp_name_t | let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 129,
"start_col": 0,
"start_line": 129
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Reflection.Typing.pp_name_t | Prims.Tot | [
"total"
] | [] | [
"FStar.Sealed.Inhabited.seal",
"Prims.string"
] | [] | false | false | false | true | false | let pp_name_default:pp_name_t =
| FStar.Sealed.Inhabited.seal "x" | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.sort_t | val sort_t : Type0 | let sort_t = FStar.Sealed.Inhabited.sealed tun | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 134,
"start_col": 0,
"start_line": 134
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Sealed.Inhabited.sealed",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.tun"
] | [] | false | false | false | true | true | let sort_t =
| FStar.Sealed.Inhabited.sealed tun | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.pp_name_t | val pp_name_t : Type0 | let pp_name_t = FStar.Sealed.Inhabited.sealed "x" | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 128,
"start_col": 0,
"start_line": 128
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Sealed.Inhabited.sealed",
"Prims.string"
] | [] | false | false | false | true | true | let pp_name_t =
| FStar.Sealed.Inhabited.sealed "x" | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.tun | val tun : FStar.Stubs.Reflection.Types.term | let tun = pack_ln Tv_Unknown | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 132,
"start_col": 0,
"start_line": 132
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Unknown"
] | [] | false | false | false | true | false | let tun =
| pack_ln Tv_Unknown | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.sort_default | val sort_default:sort_t | val sort_default:sort_t | let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 135,
"start_col": 0,
"start_line": 135
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Reflection.Typing.sort_t | Prims.Tot | [
"total"
] | [] | [
"FStar.Sealed.Inhabited.seal",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.tun"
] | [] | false | false | false | true | false | let sort_default:sort_t =
| FStar.Sealed.Inhabited.seal tun | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.map_dec | val map_dec (#a #b: _) (l: list a) (f: (x: a{x << l} -> b)) : Tot (list b) (decreases l) | val map_dec (#a #b: _) (l: list a) (f: (x: a{x << l} -> b)) : Tot (list b) (decreases l) | let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 55,
"start_col": 0,
"start_line": 48
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list a -> f: (x: a{x << l} -> b) -> Prims.Tot (Prims.list b) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.list",
"Prims.precedes",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.Typing.map_dec"
] | [
"recursion"
] | false | false | false | false | false | let rec map_dec #a #b (l: list a) (f: (x: a{x << l} -> b)) : Tot (list b) (decreases l) =
| match l with
| [] -> []
| x :: xs -> f x :: map_dec xs f | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.namedv_uniq | val namedv_uniq (x: namedv) : var | val namedv_uniq (x: namedv) : var | let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 178,
"start_col": 0,
"start_line": 176
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Stubs.Reflection.Types.namedv -> FStar.Stubs.Reflection.V2.Data.var | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__uniq",
"FStar.Stubs.Reflection.V2.Builtins.inspect_namedv",
"FStar.Stubs.Reflection.V2.Data.var"
] | [] | false | false | false | true | false | let namedv_uniq (x: namedv) : var =
| (inspect_namedv x).uniq | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binder_sort | val binder_sort : b: FStar.Stubs.Reflection.Types.binder -> FStar.Stubs.Reflection.Types.typ | let binder_sort (b:binder) =
(inspect_binder b).sort | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 181,
"start_col": 0,
"start_line": 180
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Stubs.Reflection.Types.binder -> FStar.Stubs.Reflection.Types.typ | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort",
"FStar.Stubs.Reflection.V2.Builtins.inspect_binder",
"FStar.Stubs.Reflection.Types.typ"
] | [] | false | false | false | true | false | let binder_sort (b: binder) =
| (inspect_binder b).sort | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.zip2prop | val zip2prop (#a #b: _) (f: (a -> b -> Type0)) (xs: list a) (ys: list b) : Type0 | val zip2prop (#a #b: _) (f: (a -> b -> Type0)) (xs: list a) (ys: list b) : Type0 | let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 61,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> _: b -> Type0) -> xs: Prims.list a -> ys: Prims.list b -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_True",
"Prims.l_and",
"FStar.Reflection.Typing.zip2prop",
"FStar.Pervasives.Native.tuple2",
"Prims.l_False"
] | [
"recursion"
] | false | false | false | true | true | let rec zip2prop #a #b (f: (a -> b -> Type0)) (xs: list a) (ys: list b) : Type0 =
| match xs, ys with
| [], [] -> True
| x :: xx, y :: yy -> f x y /\ zip2prop f xx yy
| _ -> False | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bv_index | val bv_index (x: bv) : var | val bv_index (x: bv) : var | let bv_index (x:bv)
: var
= (inspect_bv x).index | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 174,
"start_col": 0,
"start_line": 172
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Stubs.Reflection.Types.bv -> FStar.Stubs.Reflection.V2.Data.var | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.bv",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbv_view__item__index",
"FStar.Stubs.Reflection.V2.Builtins.inspect_bv",
"FStar.Stubs.Reflection.V2.Data.var"
] | [] | false | false | false | true | false | let bv_index (x: bv) : var =
| (inspect_bv x).index | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binder_qual | val binder_qual : b: FStar.Stubs.Reflection.Types.binder -> FStar.Stubs.Reflection.V2.Data.aqualv | let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 184,
"start_col": 0,
"start_line": 183
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Stubs.Reflection.Types.binder -> FStar.Stubs.Reflection.V2.Data.aqualv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"Prims.list",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.ppname_t",
"FStar.Stubs.Reflection.V2.Data.binder_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_binder"
] | [] | false | false | false | true | false | let binder_qual (b: binder) =
| let { qual = q } = inspect_binder b in
q | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst | val subst : Type0 | let subst = list subst_elt | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 197,
"start_col": 0,
"start_line": 197
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Reflection.Typing.subst_elt"
] | [] | false | false | false | true | true | let subst =
| list subst_elt | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.fold_left_dec | val fold_left_dec (#a #b: _) (acc: a) (l: list b) (f: (a -> x: b{x << l} -> a))
: Tot a (decreases l) | val fold_left_dec (#a #b: _) (acc: a) (l: list b) (f: (a -> x: b{x << l} -> a))
: Tot a (decreases l) | let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 46,
"start_col": 0,
"start_line": 38
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | acc: a -> l: Prims.list b -> f: (_: a -> x: b{x << l} -> a) -> Prims.Tot a | Prims.Tot | [
"total",
""
] | [] | [
"Prims.list",
"Prims.precedes",
"FStar.Reflection.Typing.fold_left_dec"
] | [
"recursion"
] | false | false | false | false | false | let rec fold_left_dec #a #b (acc: a) (l: list b) (f: (a -> x: b{x << l} -> a)) : Tot a (decreases l) =
| match l with
| [] -> acc
| x :: xs -> fold_left_dec (f acc x) xs f | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.maybe_uniq_of_term | val maybe_uniq_of_term : x: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Native.option FStar.Stubs.Reflection.V2.Data.var | let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 206,
"start_col": 0,
"start_line": 203
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Native.option FStar.Stubs.Reflection.V2.Data.var | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Pervasives.Native.Some",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Reflection.Typing.namedv_uniq",
"FStar.Stubs.Reflection.V2.Data.term_view",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let maybe_uniq_of_term (x: term) =
| match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.shift_subst | val shift_subst : x: Prims.list FStar.Reflection.Typing.subst_elt -> Prims.list FStar.Reflection.Typing.subst_elt | let shift_subst = shift_subst_n 1 | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 201,
"start_col": 0,
"start_line": 201
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.list FStar.Reflection.Typing.subst_elt -> Prims.list FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.shift_subst_n"
] | [] | false | false | false | true | false | let shift_subst =
| shift_subst_n 1 | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.shift_subst_n | val shift_subst_n : n: Prims.nat -> x: Prims.list FStar.Reflection.Typing.subst_elt
-> Prims.list FStar.Reflection.Typing.subst_elt | let shift_subst_n (n:nat) = L.map (shift_subst_elt n) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 199,
"start_col": 0,
"start_line": 199
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> x: Prims.list FStar.Reflection.Typing.subst_elt
-> Prims.list FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.List.Tot.Base.map",
"FStar.Reflection.Typing.subst_elt",
"FStar.Reflection.Typing.shift_subst_elt",
"Prims.list"
] | [] | false | false | false | true | false | let shift_subst_n (n: nat) =
| L.map (shift_subst_elt n) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.var_as_bv | val var_as_bv : v: Prims.nat -> FStar.Stubs.Reflection.Types.bv | let var_as_bv (v:nat) = pack_bv (make_bv v) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 270,
"start_col": 0,
"start_line": 270
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Prims.nat -> FStar.Stubs.Reflection.Types.bv | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Stubs.Reflection.V2.Builtins.pack_bv",
"FStar.Reflection.Typing.make_bv",
"FStar.Stubs.Reflection.Types.bv"
] | [] | false | false | false | true | false | let var_as_bv (v: nat) =
| pack_bv (make_bv v) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_total | val mk_total : t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.Types.comp | let mk_total t = pack_comp (C_Total t) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 295,
"start_col": 0,
"start_line": 295
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.Types.comp | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Builtins.pack_comp",
"FStar.Stubs.Reflection.V2.Data.C_Total",
"FStar.Stubs.Reflection.Types.comp"
] | [] | false | false | false | true | false | let mk_total t =
| pack_comp (C_Total t) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.var_as_term | val var_as_term : v: FStar.Stubs.Reflection.V2.Data.var -> FStar.Stubs.Reflection.Types.term | let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 291,
"start_col": 0,
"start_line": 291
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: FStar.Stubs.Reflection.V2.Data.var -> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Var",
"FStar.Reflection.Typing.var_as_namedv",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let var_as_term (v: var) =
| pack_ln (Tv_Var (var_as_namedv v)) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binder_of_t_q | val binder_of_t_q : t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv
-> FStar.Stubs.Reflection.Types.binder | let binder_of_t_q t q = mk_binder pp_name_default t q | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 293,
"start_col": 0,
"start_line": 293
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> q: FStar.Stubs.Reflection.V2.Data.aqualv
-> FStar.Stubs.Reflection.Types.binder | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Reflection.Typing.mk_binder",
"FStar.Reflection.Typing.pp_name_default",
"FStar.Stubs.Reflection.Types.binder"
] | [] | false | false | false | true | false | let binder_of_t_q t q =
| mk_binder pp_name_default t q | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_ghost | val mk_ghost : t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.Types.comp | let mk_ghost t = pack_comp (C_GTotal t) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 296,
"start_col": 0,
"start_line": 296
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.typ -> FStar.Stubs.Reflection.Types.comp | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Builtins.pack_comp",
"FStar.Stubs.Reflection.V2.Data.C_GTotal",
"FStar.Stubs.Reflection.Types.comp"
] | [] | false | false | false | true | false | let mk_ghost t =
| pack_comp (C_GTotal t) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.open_with_var | val open_with_var (x: var) (i: nat) : subst | val open_with_var (x: var) (i: nat) : subst | let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 307,
"start_col": 0,
"start_line": 307
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt = | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat -> FStar.Reflection.Typing.subst | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.var",
"Prims.nat",
"Prims.Cons",
"FStar.Reflection.Typing.subst_elt",
"FStar.Reflection.Typing.open_with_var_elt",
"Prims.Nil",
"FStar.Reflection.Typing.subst"
] | [] | false | false | false | true | false | let open_with_var (x: var) (i: nat) : subst =
| [open_with_var_elt x i] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_let | val mk_let : ppname: FStar.Reflection.Typing.pp_name_t ->
e1: FStar.Stubs.Reflection.Types.term ->
t1: FStar.Stubs.Reflection.Types.term ->
e2: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 66,
"end_line": 303,
"start_col": 0,
"start_line": 302
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ppname: FStar.Reflection.Typing.pp_name_t ->
e1: FStar.Stubs.Reflection.Types.term ->
t1: FStar.Stubs.Reflection.Types.term ->
e2: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.pp_name_t",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Let",
"Prims.Nil",
"FStar.Reflection.Typing.mk_simple_binder"
] | [] | false | false | false | true | false | let mk_let ppname (e1: R.term) (t1: R.term) (e2: R.term) =
| R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.extend_env | val extend_env (e: env) (x: var) (ty: term) : env | val extend_env (e: env) (x: var) (ty: term) : env | let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
}) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 4,
"end_line": 157,
"start_col": 0,
"start_line": 152
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
e: FStar.Stubs.Reflection.Types.env ->
x: FStar.Stubs.Reflection.V2.Data.var ->
ty: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.env | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V2.Derived.push_binding",
"FStar.Stubs.Reflection.V2.Data.Mkbinding",
"FStar.Reflection.Typing.seal_pp_name"
] | [] | false | false | false | true | false | let extend_env (e: env) (x: var) (ty: term) : env =
| R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty }) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_simple_binder | val mk_simple_binder (pp_name: pp_name_t) (ty: term) : simple_binder | val mk_simple_binder (pp_name: pp_name_t) (ty: term) : simple_binder | let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 150,
"start_col": 0,
"start_line": 145
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pp_name: FStar.Reflection.Typing.pp_name_t -> ty: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.V2.Data.simple_binder | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.pp_name_t",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.pack_binder",
"FStar.Stubs.Reflection.V2.Data.Mkbinder_view",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Stubs.Reflection.V2.Data.simple_binder"
] | [] | false | false | false | true | false | let mk_simple_binder (pp_name: pp_name_t) (ty: term) : simple_binder =
| pack_binder ({ ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty }) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.open_with_var_elt | val open_with_var_elt (x: var) (i: nat) : subst_elt | val open_with_var_elt (x: var) (i: nat) : subst_elt | let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x))) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 306,
"start_col": 0,
"start_line": 305
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat -> FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.var",
"Prims.nat",
"FStar.Reflection.Typing.DT",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Var",
"FStar.Reflection.Typing.var_as_namedv",
"FStar.Reflection.Typing.subst_elt"
] | [] | false | false | false | true | false | let open_with_var_elt (x: var) (i: nat) : subst_elt =
| DT i (pack_ln (Tv_Var (var_as_namedv x))) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_binder | val mk_binder (pp_name: pp_name_t) (ty: term) (q: aqualv) : binder | val mk_binder (pp_name: pp_name_t) (ty: term) (q: aqualv) : binder | let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 143,
"start_col": 0,
"start_line": 138
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pp_name: FStar.Reflection.Typing.pp_name_t ->
ty: FStar.Stubs.Reflection.Types.term ->
q: FStar.Stubs.Reflection.V2.Data.aqualv
-> FStar.Stubs.Reflection.Types.binder | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.pp_name_t",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Stubs.Reflection.V2.Builtins.pack_binder",
"FStar.Stubs.Reflection.V2.Data.Mkbinder_view",
"Prims.Nil",
"FStar.Stubs.Reflection.Types.binder"
] | [] | false | false | false | true | false | let mk_binder (pp_name: pp_name_t) (ty: term) (q: aqualv) : binder =
| pack_binder ({ ppname = pp_name; qual = q; attrs = []; sort = ty }) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.shift_subst_elt | val shift_subst_elt : n: Prims.nat -> _: FStar.Reflection.Typing.subst_elt -> FStar.Reflection.Typing.subst_elt | let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 195,
"start_col": 0,
"start_line": 192
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> _: FStar.Reflection.Typing.subst_elt -> FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Reflection.Typing.subst_elt",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.DT",
"Prims.op_Addition",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Reflection.Typing.NT",
"FStar.Reflection.Typing.ND"
] | [] | false | false | false | true | false | let shift_subst_elt (n: nat) =
| function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.constant_as_term | val constant_as_term : v: FStar.Stubs.Reflection.V2.Data.vconst -> FStar.Stubs.Reflection.Types.term | let constant_as_term (v:vconst) = pack_ln (Tv_Const v) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 530,
"start_col": 0,
"start_line": 530
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: FStar.Stubs.Reflection.V2.Data.vconst -> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.vconst",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Const",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let constant_as_term (v: vconst) =
| pack_ln (Tv_Const v) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.find_matching_subst_elt_bv | val find_matching_subst_elt_bv (s: subst) (bv: bv) : option subst_elt | val find_matching_subst_elt_bv (s: subst) (bv: bv) : option subst_elt | let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 215,
"start_col": 0,
"start_line": 208
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Reflection.Typing.subst -> bv: FStar.Stubs.Reflection.Types.bv
-> FStar.Pervasives.Native.option FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.Types.bv",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Typing.subst_elt",
"Prims.nat",
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"Prims.op_Equality",
"FStar.Reflection.Typing.bv_index",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.DT",
"Prims.bool",
"FStar.Reflection.Typing.find_matching_subst_elt_bv",
"FStar.Pervasives.Native.option"
] | [
"recursion"
] | false | false | false | true | false | let rec find_matching_subst_elt_bv (s: subst) (bv: bv) : option subst_elt =
| match s with
| [] -> None
| DT j t :: ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv
| _ :: ss -> find_matching_subst_elt_bv ss bv | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_var | val subst_var (v: namedv) (s: subst) : term | val subst_var (v: namedv) (s: subst) : term | let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 256,
"start_col": 0,
"start_line": 242
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: FStar.Stubs.Reflection.Types.namedv -> s: FStar.Reflection.Typing.subst
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Reflection.Typing.subst",
"FStar.Reflection.Typing.find_matching_subst_elt_var",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.maybe_uniq_of_term",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Var",
"FStar.Stubs.Reflection.V2.Builtins.pack_namedv",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__sort",
"FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__ppname",
"FStar.Stubs.Reflection.V2.Data.namedv_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_namedv",
"Prims.nat",
"FStar.Stubs.Reflection.V2.Data.Tv_BVar",
"FStar.Stubs.Reflection.Types.bv",
"FStar.Stubs.Reflection.V2.Builtins.pack_bv",
"FStar.Stubs.Reflection.V2.Data.Mkbv_view",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Typing.subst_elt"
] | [] | false | false | false | true | false | let subst_var (v: namedv) (s: subst) : term =
| match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k -> pack_ln (Tv_Var (pack_namedv ({ inspect_namedv v with uniq = k }))))
| Some (ND _ i) ->
let bv =
pack_bv ({ sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i })
in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.unit_fv | val unit_fv : FStar.Stubs.Reflection.Types.fv | let unit_fv = pack_fv unit_lid | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 532,
"start_col": 0,
"start_line": 532
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.fv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.unit_lid"
] | [] | false | false | false | true | false | let unit_fv =
| pack_fv unit_lid | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.var_as_namedv | val var_as_namedv (v: nat) : namedv | val var_as_namedv (v: nat) : namedv | let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 289,
"start_col": 0,
"start_line": 284
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Prims.nat -> FStar.Stubs.Reflection.Types.namedv | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Stubs.Reflection.V2.Builtins.pack_namedv",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Reflection.Typing.sort_default",
"FStar.Reflection.Typing.pp_name_default",
"FStar.Stubs.Reflection.Types.namedv"
] | [] | false | false | false | true | false | let var_as_namedv (v: nat) : namedv =
| pack_namedv ({ uniq = v; sort = sort_default; ppname = pp_name_default }) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.unit_ty | val unit_ty : FStar.Stubs.Reflection.Types.term | let unit_ty = pack_ln (Tv_FVar unit_fv) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 533,
"start_col": 0,
"start_line": 533
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.Typing.unit_fv"
] | [] | false | false | false | true | false | let unit_ty =
| pack_ln (Tv_FVar unit_fv) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.make_namedv_with_name | val make_namedv_with_name (s: pp_name_t) (n: nat) : namedv_view | val make_namedv_with_name (s: pp_name_t) (n: nat) : namedv_view | let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 282,
"start_col": 0,
"start_line": 278
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Reflection.Typing.pp_name_t -> n: Prims.nat -> FStar.Stubs.Reflection.V2.Data.namedv_view | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.pp_name_t",
"Prims.nat",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Reflection.Typing.sort_default",
"FStar.Stubs.Reflection.V2.Data.namedv_view"
] | [] | false | false | false | true | false | let make_namedv_with_name (s: pp_name_t) (n: nat) : namedv_view =
| { ppname = s; uniq = n; sort = sort_default } | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.make_bv | val make_bv (n: nat) : bv_view | val make_bv (n: nat) : bv_view | let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 262,
"start_col": 0,
"start_line": 258
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> FStar.Stubs.Reflection.V2.Data.bv_view | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Stubs.Reflection.V2.Data.Mkbv_view",
"FStar.Reflection.Typing.sort_default",
"FStar.Reflection.Typing.pp_name_default",
"FStar.Stubs.Reflection.V2.Data.bv_view"
] | [] | false | false | false | true | false | let make_bv (n: nat) : bv_view =
| { ppname = pp_name_default; index = n; sort = sort_default } | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.unit_exp | val unit_exp : FStar.Stubs.Reflection.Types.term | let unit_exp = constant_as_term C_Unit | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 531,
"start_col": 0,
"start_line": 531
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.constant_as_term",
"FStar.Stubs.Reflection.V2.Data.C_Unit"
] | [] | false | false | false | true | false | let unit_exp =
| constant_as_term C_Unit | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.u_zero | val u_zero : FStar.Stubs.Reflection.Types.universe | let u_zero = pack_universe Uv_Zero | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 537,
"start_col": 0,
"start_line": 537
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.universe | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_universe",
"FStar.Stubs.Reflection.V2.Data.Uv_Zero"
] | [] | false | false | false | true | false | let u_zero =
| pack_universe Uv_Zero | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.make_namedv | val make_namedv (n: nat) : namedv_view | val make_namedv (n: nat) : namedv_view | let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 276,
"start_col": 0,
"start_line": 272
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> FStar.Stubs.Reflection.V2.Data.namedv_view | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Reflection.Typing.sort_default",
"FStar.Reflection.Typing.pp_name_default",
"FStar.Stubs.Reflection.V2.Data.namedv_view"
] | [] | false | false | false | true | false | let make_namedv (n: nat) : namedv_view =
| { ppname = pp_name_default; uniq = n; sort = sort_default } | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.u_max | val u_max : u1: FStar.Stubs.Reflection.Types.universe -> u2: FStar.Stubs.Reflection.Types.universe
-> FStar.Stubs.Reflection.Types.universe | let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 538,
"start_col": 0,
"start_line": 538
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u1: FStar.Stubs.Reflection.Types.universe -> u2: FStar.Stubs.Reflection.Types.universe
-> FStar.Stubs.Reflection.Types.universe | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.universe",
"FStar.Stubs.Reflection.V2.Builtins.pack_universe",
"FStar.Stubs.Reflection.V2.Data.Uv_Max",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let u_max u1 u2 =
| pack_universe (Uv_Max [u1; u2]) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bool_ty | val bool_ty : FStar.Stubs.Reflection.Types.term | let bool_ty = pack_ln (Tv_FVar bool_fv) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 535,
"start_col": 0,
"start_line": 535
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_FVar",
"FStar.Reflection.Typing.bool_fv"
] | [] | false | false | false | true | false | let bool_ty =
| pack_ln (Tv_FVar bool_fv) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.make_bv_with_name | val make_bv_with_name (s: pp_name_t) (n: nat) : bv_view | val make_bv_with_name (s: pp_name_t) (n: nat) : bv_view | let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 267,
"start_col": 0,
"start_line": 263
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Reflection.Typing.pp_name_t -> n: Prims.nat -> FStar.Stubs.Reflection.V2.Data.bv_view | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.pp_name_t",
"Prims.nat",
"FStar.Stubs.Reflection.V2.Data.Mkbv_view",
"FStar.Reflection.Typing.sort_default",
"FStar.Stubs.Reflection.V2.Data.bv_view"
] | [] | false | false | false | true | false | let make_bv_with_name (s: pp_name_t) (n: nat) : bv_view =
| { ppname = s; index = n; sort = sort_default } | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bool_fv | val bool_fv : FStar.Stubs.Reflection.Types.fv | let bool_fv = pack_fv bool_lid | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 534,
"start_col": 0,
"start_line": 534
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.fv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.bool_lid"
] | [] | false | false | false | true | false | let bool_fv =
| pack_fv bool_lid | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.find_matching_subst_elt_var | val find_matching_subst_elt_var (s: subst) (v: namedv) : option subst_elt | val find_matching_subst_elt_var (s: subst) (v: namedv) : option subst_elt | let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 240,
"start_col": 0,
"start_line": 232
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Reflection.Typing.subst -> v: FStar.Stubs.Reflection.Types.namedv
-> FStar.Pervasives.Native.option FStar.Reflection.Typing.subst_elt | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Typing.subst_elt",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"Prims.op_Equality",
"FStar.Reflection.Typing.namedv_uniq",
"FStar.Pervasives.Native.Some",
"FStar.List.Tot.Base.hd",
"Prims.bool",
"FStar.Reflection.Typing.find_matching_subst_elt_var",
"FStar.Pervasives.Native.option",
"Prims.nat"
] | [
"recursion"
] | false | false | false | true | false | let rec find_matching_subst_elt_var (s: subst) (v: namedv) : option subst_elt =
| match s with
| [] -> None
| NT y _ :: rest
| ND y _ :: rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v
| _ :: rest -> find_matching_subst_elt_var rest v | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.u_succ | val u_succ : u297: FStar.Stubs.Reflection.Types.universe -> FStar.Stubs.Reflection.Types.universe | let u_succ u = pack_universe (Uv_Succ u) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 539,
"start_col": 0,
"start_line": 539
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u297: FStar.Stubs.Reflection.Types.universe -> FStar.Stubs.Reflection.Types.universe | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.universe",
"FStar.Stubs.Reflection.V2.Builtins.pack_universe",
"FStar.Stubs.Reflection.V2.Data.Uv_Succ"
] | [] | false | false | false | true | false | let u_succ u =
| pack_universe (Uv_Succ u) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.tm_type | val tm_type : u299: FStar.Stubs.Reflection.Types.universe -> FStar.Stubs.Reflection.Types.term | let tm_type u = pack_ln (Tv_Type u) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 540,
"start_col": 0,
"start_line": 540
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u299: FStar.Stubs.Reflection.Types.universe -> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.universe",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Type",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let tm_type u =
| pack_ln (Tv_Type u) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_db | val subst_db (bv: bv) (s: subst) : term | val subst_db (bv: bv) (s: subst) : term | let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 230,
"start_col": 0,
"start_line": 217
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bv: FStar.Stubs.Reflection.Types.bv -> s: FStar.Reflection.Typing.subst
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.bv",
"FStar.Reflection.Typing.subst",
"FStar.Reflection.Typing.find_matching_subst_elt_bv",
"Prims.nat",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.maybe_uniq_of_term",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Var",
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Stubs.Reflection.V2.Builtins.pack_namedv",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbv_view__item__sort",
"FStar.Stubs.Reflection.V2.Builtins.inspect_bv",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbv_view__item__ppname",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Typing.subst_elt",
"FStar.Stubs.Reflection.V2.Data.Tv_BVar"
] | [] | false | false | false | true | false | let subst_db (bv: bv) (s: subst) : term =
| match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
let v:namedv =
pack_namedv ({ sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k })
in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.eqtype_lid | val eqtype_lid:R.name | val eqtype_lid:R.name | let eqtype_lid : R.name = ["Prims"; "eqtype"] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 544,
"start_col": 0,
"start_line": 544
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.name | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | false | false | true | false | let eqtype_lid:R.name =
| ["Prims"; "eqtype"] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.tm_prop | val tm_prop : FStar.Stubs.Reflection.Types.term | let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 543,
"start_col": 0,
"start_line": 541
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_FVar",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.prop_qn"
] | [] | false | false | false | true | false | let tm_prop =
| let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.b2t_lid | val b2t_lid:R.name | val b2t_lid:R.name | let b2t_lid : R.name = ["Prims"; "b2t"] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 557,
"start_col": 0,
"start_line": 557
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.name | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | false | false | true | false | let b2t_lid:R.name =
| ["Prims"; "b2t"] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.true_bool | val true_bool : FStar.Stubs.Reflection.Types.term | let true_bool = pack_ln (Tv_Const C_True) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 546,
"start_col": 0,
"start_line": 546
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Const",
"FStar.Stubs.Reflection.V2.Data.C_True"
] | [] | false | false | false | true | false | let true_bool =
| pack_ln (Tv_Const C_True) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.false_bool | val false_bool : FStar.Stubs.Reflection.Types.term | let false_bool = pack_ln (Tv_Const C_False) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 547,
"start_col": 0,
"start_line": 547
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Const",
"FStar.Stubs.Reflection.V2.Data.C_False"
] | [] | false | false | false | true | false | let false_bool =
| pack_ln (Tv_Const C_False) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.eq2 | val eq2 (u: universe) (t v0 v1: term) : term | val eq2 (u: universe) (t v0 v1: term) : term | let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2 | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 555,
"start_col": 0,
"start_line": 548
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u307: FStar.Stubs.Reflection.Types.universe ->
t: FStar.Stubs.Reflection.Types.term ->
v0: FStar.Stubs.Reflection.Types.term ->
v1: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.universe",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"FStar.Stubs.Reflection.V2.Data.Q_Implicit",
"FStar.Stubs.Reflection.V2.Data.Tv_UInst",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.eq2_qn"
] | [] | false | false | false | true | false | let eq2 (u: universe) (t v0 v1: term) : term =
| let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2 | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.b2t_fv | val b2t_fv:R.fv | val b2t_fv:R.fv | let b2t_fv : R.fv = R.pack_fv b2t_lid | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 558,
"start_col": 0,
"start_line": 558
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.fv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Typing.b2t_lid"
] | [] | false | false | false | true | false | let b2t_fv:R.fv =
| R.pack_fv b2t_lid | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binder_offset_patterns | val binder_offset_patterns (ps: list (pattern & bool)) : nat | val binder_offset_patterns (ps: list (pattern & bool)) : nat | let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 330,
"start_col": 0,
"start_line": 312
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ps: Prims.list (FStar.Stubs.Reflection.V2.Data.pattern * Prims.bool) -> Prims.nat | Prims.Tot | [
"total"
] | [
"binder_offset_patterns",
"binder_offset_pattern"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.pattern",
"Prims.bool",
"Prims.op_Addition",
"Prims.nat",
"FStar.Reflection.Typing.binder_offset_patterns",
"FStar.Reflection.Typing.binder_offset_pattern"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec binder_offset_patterns (ps: list (pattern & bool)) : nat =
| match ps with
| [] -> 0
| (p, b) :: ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binder_offset_pattern | val binder_offset_pattern (p: pattern) : nat | val binder_offset_pattern (p: pattern) : nat | let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 330,
"start_col": 0,
"start_line": 312
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.Stubs.Reflection.V2.Data.pattern -> Prims.nat | Prims.Tot | [
"total"
] | [
"binder_offset_patterns",
"binder_offset_pattern"
] | [
"FStar.Stubs.Reflection.V2.Data.pattern",
"FStar.Stubs.Reflection.V2.Data.vconst",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.term",
"FStar.Sealed.sealed",
"FStar.Stubs.Reflection.V2.Data.ppname_t",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Data.universes",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Reflection.Typing.binder_offset_patterns",
"Prims.nat"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec binder_offset_pattern (p: pattern) : nat =
| match p with
| Pat_Constant _ | Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats -> binder_offset_patterns subpats | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.ln | val ln : t: FStar.Stubs.Reflection.Types.term -> Prims.bool | let ln (t:term) = ln' t (-1) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 857,
"start_col": 0,
"start_line": 857
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.ln'",
"Prims.op_Minus",
"Prims.bool"
] | [] | false | false | false | true | false | let ln (t: term) =
| ln' t (- 1) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.open_comp_typ | val open_comp_typ : c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0 | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 1001,
"start_col": 0,
"start_line": 1000
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Reflection.Typing.open_comp_typ'",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let open_comp_typ (c: comp_typ) (x: var) =
| open_comp_typ' c x 0 | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_if | val mk_if (scrutinee then_ else_: R.term) : R.term | val mk_if (scrutinee then_ else_: R.term) : R.term | let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)]) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 985,
"start_col": 0,
"start_line": 983
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
scrutinee: FStar.Stubs.Reflection.Types.term ->
then_: FStar.Stubs.Reflection.Types.term ->
else_: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Match",
"FStar.Pervasives.Native.None",
"FStar.Stubs.Reflection.Types.match_returns_ascription",
"Prims.Cons",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.pattern",
"FStar.Stubs.Reflection.V2.Data.Pat_Constant",
"FStar.Stubs.Reflection.V2.Data.C_True",
"FStar.Stubs.Reflection.V2.Data.C_False",
"Prims.Nil"
] | [] | false | false | false | true | false | let mk_if (scrutinee then_ else_: R.term) : R.term =
| pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.freevars_comp_typ | val freevars_comp_typ : c: FStar.Reflection.Typing.comp_typ -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var | let freevars_comp_typ (c:comp_typ) = freevars (snd c) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 1003,
"start_col": 0,
"start_line": 1003
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Reflection.Typing.freevars",
"FStar.Pervasives.Native.snd",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Set.set",
"FStar.Stubs.Reflection.V2.Data.var"
] | [] | false | false | false | true | false | let freevars_comp_typ (c: comp_typ) =
| freevars (snd c) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.ln_comp | val ln_comp : c: FStar.Stubs.Reflection.Types.comp -> Prims.bool | let ln_comp (c:comp) = ln'_comp c (-1) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 858,
"start_col": 0,
"start_line": 858
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Stubs.Reflection.Types.comp -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.comp",
"FStar.Reflection.Typing.ln'_comp",
"Prims.op_Minus",
"Prims.bool"
] | [] | false | false | false | true | false | let ln_comp (c: comp) =
| ln'_comp c (- 1) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.close_comp_typ | val close_comp_typ : c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0 | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 995,
"start_col": 0,
"start_line": 994
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Reflection.Typing.close_comp_typ'",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let close_comp_typ (c: comp_typ) (x: var) =
| close_comp_typ' c x 0 | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.close_comp_typ' | val close_comp_typ' : c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 992,
"start_col": 0,
"start_line": 991
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Stubs.Reflection.V2.Data.var",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Reflection.Typing.subst_term",
"FStar.Pervasives.Native.snd",
"Prims.Cons",
"FStar.Reflection.Typing.subst_elt",
"FStar.Reflection.Typing.ND",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let close_comp_typ' (c: comp_typ) (x: var) (i: nat) =
| fst c, subst_term (snd c) [ND x i] | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.open_comp_typ' | val open_comp_typ' : c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 998,
"start_col": 0,
"start_line": 997
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> x: FStar.Stubs.Reflection.V2.Data.var -> i: Prims.nat
-> FStar.Stubs.TypeChecker.Core.tot_or_ghost * FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Stubs.Reflection.V2.Data.var",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Reflection.Typing.subst_term",
"FStar.Pervasives.Native.snd",
"FStar.Reflection.Typing.open_with_var",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let open_comp_typ' (c: comp_typ) (x: var) (i: nat) =
| fst c, subst_term (snd c) (open_with_var x i) | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binding | val binding : Type0 | let binding = var & term | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 1017,
"start_col": 0,
"start_line": 1017
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | true | let binding =
| var & term | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bindings | val bindings : Type0 | let bindings = list binding | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 1018,
"start_col": 0,
"start_line": 1018
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Reflection.Typing.binding"
] | [] | false | false | false | true | true | let bindings =
| list binding | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.b2t_ty | val b2t_ty:R.term | val b2t_ty:R.term | let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 114,
"end_line": 559,
"start_col": 0,
"start_line": 559
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Arrow",
"FStar.Reflection.Typing.mk_binder",
"FStar.Sealed.seal",
"Prims.string",
"FStar.Reflection.Typing.bool_ty",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"FStar.Reflection.Typing.mk_total",
"FStar.Reflection.Typing.tm_type",
"FStar.Reflection.Typing.u_zero"
] | [] | false | false | false | true | false | let b2t_ty:R.term =
| R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.rename_bindings | val rename_bindings : bs: Prims.list (_ * FStar.Stubs.Reflection.Types.term) ->
x: FStar.Stubs.Reflection.V2.Data.var ->
y: FStar.Stubs.Reflection.V2.Data.var
-> Prims.list (_ * FStar.Stubs.Reflection.Types.term) | let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 1019,
"start_col": 0,
"start_line": 1019
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bs: Prims.list (_ * FStar.Stubs.Reflection.Types.term) ->
x: FStar.Stubs.Reflection.V2.Data.var ->
y: FStar.Stubs.Reflection.V2.Data.var
-> Prims.list (_ * FStar.Stubs.Reflection.Types.term) | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Typing.rename"
] | [] | false | false | false | true | false | let rename_bindings bs x y =
| FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.is_non_informative_fv | val is_non_informative_fv (f: fv) : bool | val is_non_informative_fv (f: fv) : bool | let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 1036,
"start_col": 0,
"start_line": 1035
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: FStar.Stubs.Reflection.Types.fv -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.fv",
"FStar.Reflection.Typing.is_non_informative_name",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"Prims.bool"
] | [] | false | false | false | true | false | let is_non_informative_fv (f: fv) : bool =
| is_non_informative_name (inspect_fv f) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_binder | val subst_binder (b: binder) (ss: subst)
: Tot (b': binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) | val subst_binder (b: binder) (ss: subst)
: Tot (b': binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Stubs.Reflection.Types.binder -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot
(b':
FStar.Stubs.Reflection.Types.binder
{ FStar.Stubs.Reflection.V2.Data.binder_is_simple b ==>
FStar.Stubs.Reflection.V2.Data.binder_is_simple b' }) | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.Types.binder",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.V2.Builtins.pack_binder",
"FStar.Stubs.Reflection.V2.Data.Mkbinder_view",
"FStar.Reflection.Typing.subst_term",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual",
"FStar.Reflection.Typing.subst_terms",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname",
"FStar.Stubs.Reflection.V2.Data.binder_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_binder",
"Prims.l_imp",
"Prims.b2t",
"FStar.Stubs.Reflection.V2.Data.binder_is_simple"
] | [
"mutual recursion"
] | false | false | false | false | false | let rec subst_binder (b: binder) (ss: subst)
: Tot (b': binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) =
| let bndr = inspect_binder b in
pack_binder ({
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.close_term_bs | val close_term_bs (bs: list binding) (t: term) : term | val close_term_bs (bs: list binding) (t: term) : term | let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 1048,
"start_col": 0,
"start_line": 1047
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bs: Prims.list FStar.Reflection.Typing.binding -> t: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Reflection.Typing.binding",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.close_term_vs",
"FStar.List.Tot.Base.map",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Pervasives.Native.fst"
] | [] | false | false | false | true | false | let close_term_bs (bs: list binding) (t: term) : term =
| close_term_vs (List.Tot.map fst bs) t | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.close_term_vs | val close_term_vs (vs: list var) (t: term) : term | val close_term_vs (vs: list var) (t: term) : term | let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 1045,
"start_col": 0,
"start_line": 1044
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | vs: Prims.list FStar.Stubs.Reflection.V2.Data.var -> t: FStar.Stubs.Reflection.Types.term
-> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.__close_term_vs"
] | [] | false | false | false | true | false | let close_term_vs (vs: list var) (t: term) : term =
| __close_term_vs 0 vs t | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.refl_bindings_to_bindings | val refl_bindings_to_bindings (bs: list R.binding) : list binding | val refl_bindings_to_bindings (bs: list R.binding) : list binding | let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 1054,
"start_col": 0,
"start_line": 1053
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bs: Prims.list FStar.Stubs.Reflection.V2.Data.binding -> Prims.list FStar.Reflection.Typing.binding | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__uniq",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__sort",
"FStar.Reflection.Typing.binding"
] | [] | false | false | false | true | false | let refl_bindings_to_bindings (bs: list R.binding) : list binding =
| L.map (fun b -> b.uniq, b.sort) bs | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.mk_comp | val mk_comp (c: comp_typ) : R.comp | val mk_comp (c: comp_typ) : R.comp | let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 1008,
"start_col": 0,
"start_line": 1005
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Reflection.Typing.comp_typ -> FStar.Stubs.Reflection.Types.comp | Prims.Tot | [
"total"
] | [] | [
"FStar.Reflection.Typing.comp_typ",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Reflection.Typing.mk_total",
"FStar.Pervasives.Native.snd",
"FStar.Reflection.Typing.mk_ghost",
"FStar.Stubs.Reflection.Types.comp"
] | [] | false | false | false | true | false | let mk_comp (c: comp_typ) : R.comp =
| match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_term | val subst_term (t: term) (ss: subst) : Tot term (decreases t) | val subst_term (t: term) (ss: subst) : Tot term (decreases t) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Data.universes",
"FStar.Stubs.Reflection.Types.universe",
"FStar.Stubs.Reflection.V2.Data.vconst",
"FStar.Stubs.Reflection.Types.namedv",
"FStar.Reflection.Typing.subst_var",
"FStar.Stubs.Reflection.Types.bv",
"FStar.Reflection.Typing.subst_db",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_App",
"FStar.Reflection.Typing.subst_term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.V2.Data.Tv_Abs",
"FStar.Reflection.Typing.shift_subst",
"Prims.l_imp",
"Prims.b2t",
"FStar.Stubs.Reflection.V2.Data.binder_is_simple",
"FStar.Reflection.Typing.subst_binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Reflection.V2.Data.Tv_Arrow",
"FStar.Reflection.Typing.subst_comp",
"FStar.Stubs.Reflection.V2.Data.simple_binder",
"FStar.Stubs.Reflection.V2.Data.Tv_Refine",
"Prims.nat",
"FStar.Stubs.Reflection.Types.ctx_uvar_and_subst",
"FStar.Stubs.Reflection.V2.Data.Tv_Uvar",
"FStar.Reflection.Typing.subst_ctx_uvar_and_subst",
"Prims.bool",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.Tv_Let",
"FStar.Reflection.Typing.subst_terms",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.match_returns_ascription",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Stubs.Reflection.V2.Data.Tv_Match",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.subst_match_returns",
"FStar.Reflection.Typing.subst_branches",
"FStar.Stubs.Reflection.V2.Data.Tv_AscribedT",
"FStar.Stubs.Reflection.V2.Data.Tv_AscribedC"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_term (t: term) (ss: subst) : Tot term (decreases t) =
| match inspect_ln t with
| Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf then subst_term def (shift_subst ss) else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.apply_term_ctxt | val apply_term_ctxt (e: term_ctxt) (t: term) : Tot term (decreases e) | val apply_term_ctxt (e: term_ctxt) (t: term) : Tot term (decreases e) | let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 902,
"start_col": 0,
"start_line": 898
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Reflection.Typing.term_ctxt -> t: FStar.Stubs.Reflection.Types.term
-> Prims.Tot FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total",
""
] | [] | [
"FStar.Reflection.Typing.term_ctxt",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_App",
"FStar.Reflection.Typing.apply_term_ctxt",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Pervasives.Native.Mktuple2"
] | [
"recursion"
] | false | false | false | true | false | let rec apply_term_ctxt (e: term_ctxt) (t: term) : Tot term (decreases e) =
| match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_args | val subst_args (ts: list argv) (ss: subst) : Tot (list argv) (decreases ts) | val subst_args (ts: list argv) (ss: subst) : Tot (list argv) (decreases ts) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Prims.list FStar.Stubs.Reflection.V2.Data.argv -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot (Prims.list FStar.Stubs.Reflection.V2.Data.argv) | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Reflection.Typing.subst",
"Prims.Nil",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Typing.subst_term",
"FStar.Reflection.Typing.subst_args"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_args (ts: list argv) (ss: subst) : Tot (list argv) (decreases ts) =
| match ts with
| [] -> []
| (t, q) :: ts -> (subst_term t ss, q) :: subst_args ts ss | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_comp | val subst_comp (c: comp) (ss: subst) : Tot comp (decreases c) | val subst_comp (c: comp) (ss: subst) : Tot comp (decreases c) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Stubs.Reflection.Types.comp -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot FStar.Stubs.Reflection.Types.comp | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.Types.comp",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.V2.Builtins.inspect_comp",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Builtins.pack_comp",
"FStar.Stubs.Reflection.V2.Data.C_Total",
"FStar.Reflection.Typing.subst_term",
"FStar.Stubs.Reflection.V2.Data.C_GTotal",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.C_Lemma",
"FStar.Stubs.Reflection.V2.Data.universes",
"FStar.Stubs.Reflection.Types.name",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Stubs.Reflection.V2.Data.C_Eff",
"FStar.Reflection.Typing.subst_args",
"FStar.Reflection.Typing.subst_terms"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_comp (c: comp) (ss: subst) : Tot comp (decreases c) =
| match inspect_comp c with
| C_Total t -> pack_comp (C_Total (subst_term t ss))
| C_GTotal t -> pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_pattern | val subst_pattern (p: pattern) (ss: subst) : Tot pattern (decreases p) | val subst_pattern (p: pattern) (ss: subst) : Tot pattern (decreases p) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.Stubs.Reflection.V2.Data.pattern -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot FStar.Stubs.Reflection.V2.Data.pattern | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.V2.Data.pattern",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.V2.Data.vconst",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.V2.Data.universes",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Stubs.Reflection.V2.Data.Pat_Cons",
"FStar.Reflection.Typing.subst_patterns",
"FStar.Sealed.sealed",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.ppname_t",
"FStar.Stubs.Reflection.V2.Data.Pat_Var",
"FStar.Stubs.Reflection.V2.Data.Pat_Dot_Term",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.subst_term"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_pattern (p: pattern) (ss: subst) : Tot pattern (decreases p) =
| match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s -> Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term
(match topt with
| None -> None
| Some t -> Some (subst_term t ss)) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bindings_ok_for_branch_N | val bindings_ok_for_branch_N : g: FStar.Stubs.Reflection.Types.env ->
bss: Prims.list (Prims.list FStar.Stubs.Reflection.V2.Data.binding) ->
brs: Prims.list FStar.Stubs.Reflection.V2.Data.branch
-> Type0 | let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 1112,
"start_col": 0,
"start_line": 1111
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: FStar.Stubs.Reflection.Types.env ->
bss: Prims.list (Prims.list FStar.Stubs.Reflection.V2.Data.binding) ->
brs: Prims.list FStar.Stubs.Reflection.V2.Data.branch
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Reflection.Typing.zip2prop",
"FStar.Reflection.Typing.bindings_ok_for_branch"
] | [] | false | false | false | true | true | let bindings_ok_for_branch_N (g: env) (bss: list (list R.binding)) (brs: list branch) =
| zip2prop (bindings_ok_for_branch g) bss brs | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.bindings_ok_for_branch | val bindings_ok_for_branch (g: env) (bs: list R.binding) (br: branch) : Type0 | val bindings_ok_for_branch (g: env) (bs: list R.binding) (br: branch) : Type0 | let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 1109,
"start_col": 0,
"start_line": 1108
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: FStar.Stubs.Reflection.Types.env ->
bs: Prims.list FStar.Stubs.Reflection.V2.Data.binding ->
br: FStar.Stubs.Reflection.V2.Data.branch
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Reflection.Typing.bindings_ok_for_pat",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.V2.Data.pattern",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | true | let bindings_ok_for_branch (g: env) (bs: list R.binding) (br: branch) : Type0 =
| bindings_ok_for_pat g bs (fst br) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_terms | val subst_terms (ts: list term) (ss: subst)
: Tot (ts': list term {Nil? ts ==> Nil? ts'}) (decreases ts) | val subst_terms (ts: list term) (ss: subst)
: Tot (ts': list term {Nil? ts ==> Nil? ts'}) (decreases ts) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Prims.list FStar.Stubs.Reflection.Types.term -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot (ts': Prims.list FStar.Stubs.Reflection.Types.term {Nil? ts ==> Nil? ts'}) | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.subst",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.Typing.subst_term",
"FStar.Reflection.Typing.subst_terms",
"Prims.l_imp",
"Prims.b2t",
"Prims.uu___is_Nil"
] | [
"mutual recursion"
] | false | false | false | false | false | let rec subst_terms (ts: list term) (ss: subst)
: Tot (ts': list term {Nil? ts ==> Nil? ts'}) (decreases ts) =
| match ts with
| [] -> []
| t :: ts -> subst_term t ss :: subst_terms ts ss | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_branch | val subst_branch (br: branch) (ss: subst) : Tot branch (decreases br) | val subst_branch (br: branch) (ss: subst) : Tot branch (decreases br) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | br: FStar.Stubs.Reflection.V2.Data.branch -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot FStar.Stubs.Reflection.V2.Data.branch | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.V2.Data.pattern",
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Typing.subst_term",
"FStar.Reflection.Typing.shift_subst_n",
"Prims.nat",
"FStar.Reflection.Typing.binder_offset_pattern",
"FStar.Reflection.Typing.subst_pattern"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_branch (br: branch) (ss: subst) : Tot branch (decreases br) =
| let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.binding_to_namedv | val binding_to_namedv (b: R.binding) : Tot namedv | val binding_to_namedv (b: R.binding) : Tot namedv | let binding_to_namedv (b:R.binding) : Tot namedv =
pack_namedv {
RD.uniq = b.uniq;
RD.sort = seal b.sort;
RD.ppname = b.ppname;
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 1119,
"start_col": 0,
"start_line": 1114
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br)
let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Stubs.Reflection.V2.Data.binding -> FStar.Stubs.Reflection.Types.namedv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Reflection.V2.Builtins.pack_namedv",
"FStar.Stubs.Reflection.V2.Data.Mknamedv_view",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__uniq",
"FStar.Sealed.seal",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__sort",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__ppname",
"FStar.Stubs.Reflection.Types.namedv"
] | [] | false | false | false | true | false | let binding_to_namedv (b: R.binding) : Tot namedv =
| pack_namedv ({ RD.uniq = b.uniq; RD.sort = seal b.sort; RD.ppname = b.ppname }) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_patterns | val subst_patterns (ps: list (pattern & bool)) (ss: subst)
: Tot (list (pattern & bool)) (decreases ps) | val subst_patterns (ps: list (pattern & bool)) (ss: subst)
: Tot (list (pattern & bool)) (decreases ps) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ps: Prims.list (FStar.Stubs.Reflection.V2.Data.pattern * Prims.bool) ->
ss: FStar.Reflection.Typing.subst
-> Prims.Tot (Prims.list (FStar.Stubs.Reflection.V2.Data.pattern * Prims.bool)) | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.pattern",
"Prims.bool",
"FStar.Reflection.Typing.subst",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Typing.subst_patterns",
"FStar.Reflection.Typing.shift_subst_n",
"FStar.Reflection.Typing.subst_pattern",
"Prims.nat",
"FStar.Reflection.Typing.binder_offset_pattern"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_patterns (ps: list (pattern & bool)) (ss: subst)
: Tot (list (pattern & bool)) (decreases ps) =
| match ps with
| [] -> ps
| (p, b) :: ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p, b) :: ps | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_branches | val subst_branches (brs: list branch) (ss: subst) : Tot (list branch) (decreases brs) | val subst_branches (brs: list branch) (ss: subst) : Tot (list branch) (decreases brs) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | brs: Prims.list FStar.Stubs.Reflection.V2.Data.branch -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot (Prims.list FStar.Stubs.Reflection.V2.Data.branch) | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Reflection.Typing.subst",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.Typing.subst_branch",
"FStar.Reflection.Typing.subst_branches"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_branches (brs: list branch) (ss: subst) : Tot (list branch) (decreases brs) =
| match brs with
| [] -> []
| br :: brs -> subst_branch br ss :: subst_branches brs ss | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.subst_match_returns | val subst_match_returns (m: match_returns_ascription) (ss: subst)
: Tot match_returns_ascription (decreases m) | val subst_match_returns (m: match_returns_ascription) (ss: subst)
: Tot match_returns_ascription (decreases m) | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 496,
"start_col": 0,
"start_line": 332
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: FStar.Stubs.Reflection.Types.match_returns_ascription -> ss: FStar.Reflection.Typing.subst
-> Prims.Tot FStar.Stubs.Reflection.Types.match_returns_ascription | Prims.Tot | [
"total",
""
] | [
"subst_term",
"subst_binder",
"subst_comp",
"subst_terms",
"subst_args",
"subst_patterns",
"subst_pattern",
"subst_branch",
"subst_branches",
"subst_match_returns"
] | [
"FStar.Stubs.Reflection.Types.match_returns_ascription",
"FStar.Reflection.Typing.subst",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Pervasives.either",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.subst_term",
"FStar.Reflection.Typing.shift_subst",
"FStar.Pervasives.Inl",
"FStar.Pervasives.Inr",
"FStar.Reflection.Typing.subst_comp",
"Prims.l_imp",
"Prims.b2t",
"FStar.Stubs.Reflection.V2.Data.binder_is_simple",
"FStar.Reflection.Typing.subst_binder"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec subst_match_returns (m: match_returns_ascription) (ss: subst)
: Tot match_returns_ascription (decreases m) =
| let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.simplify_umax | val simplify_umax
(#g: R.env)
(#t: R.term)
(#u: R.universe)
(d: typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u) | val simplify_umax
(#g: R.env)
(#t: R.term)
(#u: R.universe)
(d: typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u) | let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe)
(d:typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u)
= let ue
: univ_eq (u_max u u) u
= UN_MaxLeq u u (UNLEQ_Refl u)
in
let du : related g (tm_type (u_max u u)) R_Eq (tm_type u)
= Rel_univ g (u_max u u) u ue in
let du : related g (tm_type (u_max u u)) R_Sub (tm_type u)
= Rel_equiv _ _ _ _ du in
T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 1524,
"start_col": 0,
"start_line": 1513
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br)
let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs
let binding_to_namedv (b:R.binding) : Tot namedv =
pack_namedv {
RD.uniq = b.uniq;
RD.sort = seal b.sort;
RD.ppname = b.ppname;
}
(* Elaborates the p pattern into a term, using the bs bindings for the
pattern variables. The resulting term is properly scoped only on an
environment which contains all of bs. See for instance the branch_typing
judg. Returns an option, since this can fail if e.g. there are not
enough bindings, and returns the list of unused binders as well, which
should be empty if the list of binding was indeed ok. *)
let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) =
match p, bs with
| Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs)
| Pat_Cons fv univs subpats, bs ->
let head = pack_ln (Tv_FVar fv) in
fold_left_dec
(Some (head, bs))
subpats
(fun st pi ->
let (p,i) = pi in
match st with | None -> None | Some (head, bs) ->
match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs'))
| Pat_Var _ _, b::bs ->
Some (pack_ln (Tv_Var (binding_to_namedv b)), bs)
| Pat_Dot_Term (Some t), _ -> Some (t, bs)
| Pat_Dot_Term None, _ -> None
| _ -> None
[@@ no_auto_projectors]
noeq
type typing : env -> term -> comp_typ -> Type0 =
| T_Token :
g:env ->
e:term ->
c:comp_typ ->
squash (T.typing_token g e c) ->
typing g e c
| T_Var :
g:env ->
x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } ->
typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x)))
| T_FVar :
g:env ->
x:fv { Some? (lookup_fvar g x) } ->
typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x))
| T_UInst :
g:env ->
x:fv ->
us:list universe { Some? (lookup_fvar_uinst g x us) } ->
typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us))
| T_Const:
g:env ->
v:vconst ->
t:term ->
constant_typing v t ->
typing g (constant_as_term v) (T.E_Total, t)
| T_Abs :
g:env ->
x:var { None? (lookup_bvar g x) } ->
ty:term ->
body:term { ~(x `Set.mem` freevars body) } ->
body_c:comp_typ ->
u:universe ->
pp_name:pp_name_t ->
q:aqualv ->
ty_eff:T.tot_or_ghost ->
typing g ty (ty_eff, tm_type u) ->
typing (extend_env g x ty) (open_term body x) body_c ->
typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body))
(T.E_Total,
pack_ln (Tv_Arrow (mk_binder pp_name ty q)
(mk_comp (close_comp_typ body_c x))))
| T_App :
g:env ->
e1:term ->
e2:term ->
x:binder ->
t:term ->
eff:T.tot_or_ghost ->
typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) ->
typing g e2 (eff, binder_sort x) ->
typing g (pack_ln (Tv_App e1 (e2, binder_qual x)))
(eff, open_with t e2)
| T_Let:
g:env ->
x:var { None? (lookup_bvar g x) } ->
e1:term ->
t1:typ ->
e2:term ->
t2:typ ->
eff:T.tot_or_ghost ->
pp_name:pp_name_t ->
typing g e1 (eff, t1) ->
typing (extend_env g x t1) (open_term e2 x) (eff, t2) ->
typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1)
| T_Arrow:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t1:term ->
t2:term { ~(x `Set.mem` freevars t2) } ->
u1:universe ->
u2:universe ->
pp_name:pp_name_t ->
q:aqualv ->
eff:T.tot_or_ghost ->
t1_eff:T.tot_or_ghost ->
t2_eff:T.tot_or_ghost ->
typing g t1 (t1_eff, tm_type u1) ->
typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) ->
typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2))))
(T.E_Total, tm_type (u_max u1 u2))
| T_Refine:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t:term ->
e:term { ~(x `Set.mem` freevars e) } ->
u1:universe ->
u2:universe ->
t_eff:T.tot_or_ghost ->
e_eff:T.tot_or_ghost ->
typing g t (t_eff, tm_type u1) ->
typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) ->
typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1)
| T_PropIrrelevance:
g:env ->
e:term ->
t:term ->
e_eff:T.tot_or_ghost ->
t_eff:T.tot_or_ghost ->
typing g e (e_eff, t) ->
typing g t (t_eff, tm_prop) ->
typing g (`()) (T.E_Total, t)
| T_Sub:
g:env ->
e:term ->
c:comp_typ ->
c':comp_typ ->
typing g e c ->
sub_comp g c c' ->
typing g e c'
| T_If:
g:env ->
scrutinee:term ->
then_:term ->
else_:term ->
ty:term ->
u_ty:universe ->
hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } ->
eff:T.tot_or_ghost ->
ty_eff:T.tot_or_ghost ->
typing g scrutinee (eff, bool_ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) ->
typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp
typing g (mk_if scrutinee then_ else_) (eff, ty)
| T_Match:
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc : term ->
ty_eff:T.tot_or_ghost ->
typing g sc_ty (ty_eff, tm_type sc_u) ->
eff:T.tot_or_ghost ->
typing g sc (eff, sc_ty) ->
branches:list branch ->
ty:comp_typ ->
bnds:list (list R.binding) ->
complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns
branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type
typing g (pack_ln (Tv_Match sc None branches)) ty
and related : env -> term -> relation -> term -> Type0 =
| Rel_refl:
g:env ->
t:term ->
rel:relation ->
related g t rel t
| Rel_sym:
g:env ->
t0:term ->
t1:term ->
related g t0 R_Eq t1 ->
related g t1 R_Eq t0
| Rel_trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
rel:relation ->
related g t0 rel t1 ->
related g t1 rel t2 ->
related g t0 rel t2
| Rel_univ:
g:env ->
u:universe ->
v:universe ->
univ_eq u v ->
related g (tm_type u) R_Eq (tm_type v)
| Rel_beta:
g:env ->
t:typ ->
q:aqualv ->
e:term { ln' e 0 } ->
arg:term { ln arg } ->
related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q)))
R_Eq
(subst_term e [ DT 0 arg ])
| Rel_eq_token:
g:env ->
t0:term ->
t1:term ->
squash (T.equiv_token g t0 t1) ->
related g t0 R_Eq t1
| Rel_subtyping_token:
g:env ->
t0:term ->
t1:term ->
squash (T.subtyping_token g t0 t1) ->
related g t0 R_Sub t1
| Rel_equiv:
g:env ->
t0:term ->
t1:term ->
rel:relation ->
related g t0 R_Eq t1 ->
related g t0 rel t1
| Rel_arrow:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
c1:comp_typ ->
c2:comp_typ ->
rel:relation ->
x:var{
None? (lookup_bvar g x) /\
~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2))
} ->
related g t2 rel t1 ->
related_comp (extend_env g x t2)
(open_comp_typ c1 x)
rel
(open_comp_typ c2 x) ->
related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2)
| Rel_abs:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
e1:term ->
e2:term ->
x:var{
None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2))
} ->
related g t1 R_Eq t2 ->
related (extend_env g x t1)
(subst_term e1 (open_with_var x 0))
R_Eq
(subst_term e2 (open_with_var x 0)) ->
related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2)
| Rel_ctxt:
g:env ->
t0:term ->
t1:term ->
ctxt:term_ctxt ->
related g t0 R_Eq t1 ->
related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1)
and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 =
| Relc_typ:
g:env ->
t0:term ->
t1:term ->
eff:T.tot_or_ghost ->
rel:relation ->
related g t0 rel t1 ->
related_comp g (eff, t0) rel (eff, t1)
| Relc_total_ghost:
g:env ->
t:term ->
related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t)
| Relc_ghost_total:
g:env ->
t:term ->
non_informative g t ->
related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t)
and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (brs:list branch) -> (bnds : list (list R.binding)) -> Type0
=
(* This judgement only enforces that branch_typing holds for every
element of brs and its respective bnds (which must have the same
length). *)
| BT_Nil :
branches_typing g sc_u sc_ty sc rty [] []
| BT_S :
br : branch ->
bnds : list R.binding ->
pf : branch_typing g sc_u sc_ty sc rty br bnds ->
rest_br : list branch ->
rest_bnds : list (list R.binding) ->
rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds ->
branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds)
and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (br : branch) -> (bnds : list R.binding) -> Type0
=
| BO :
pat : pattern ->
bnds : list R.binding{bindings_ok_for_pat g bnds pat} ->
hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} ->
body:term ->
_ : squash (Some? (elaborate_pat pat bnds)) ->
typing (extend_env
(extend_env_l g (refl_bindings_to_bindings bnds))
hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds))))
)
body rty ->
branch_typing g sc_u sc_ty sc rty
(pat, close_term_bs (refl_bindings_to_bindings bnds) body)
bnds
and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 =
| MC_Tok :
env:_ ->
sc:_ ->
ty:_ ->
pats:_ ->
bnds:_ ->
squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds
and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2
and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2
and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2
type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t)
type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t)
val subtyping_token_renaming (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0))
(rename t0 x y)
(rename t1 x y)
val subtyping_token_weakening (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
d:
FStar.Reflection.Typing.typing g
t
(FStar.Stubs.TypeChecker.Core.E_Total,
FStar.Reflection.Typing.tm_type (FStar.Reflection.Typing.u_max u2359 u2359))
-> FStar.Reflection.Typing.typing g
t
(FStar.Stubs.TypeChecker.Core.E_Total,
FStar.Reflection.Typing.tm_type u2359) | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.universe",
"FStar.Reflection.Typing.typing",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.TypeChecker.Core.E_Total",
"FStar.Reflection.Typing.tm_type",
"FStar.Reflection.Typing.u_max",
"FStar.Reflection.Typing.T_Sub",
"FStar.Reflection.Typing.Relc_typ",
"FStar.Reflection.Typing.R_Sub",
"FStar.Reflection.Typing.related",
"FStar.Reflection.Typing.Rel_equiv",
"FStar.Reflection.Typing.R_Eq",
"FStar.Reflection.Typing.Rel_univ",
"FStar.Reflection.Typing.univ_eq",
"FStar.Reflection.Typing.UN_MaxLeq",
"FStar.Reflection.Typing.UNLEQ_Refl"
] | [] | false | false | false | false | false | let simplify_umax
(#g: R.env)
(#t: R.term)
(#u: R.universe)
(d: typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u) =
| let ue:univ_eq (u_max u u) u = UN_MaxLeq u u (UNLEQ_Refl u) in
let du:related g (tm_type (u_max u u)) R_Eq (tm_type u) = Rel_univ g (u_max u u) u ue in
let du:related g (tm_type (u_max u u)) R_Sub (tm_type u) = Rel_equiv _ _ _ _ du in
T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du) | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.__close_term_vs | val __close_term_vs (i: nat) (vs: list var) (t: term) : Tot term (decreases vs) | val __close_term_vs (i: nat) (vs: list var) (t: term) : Tot term (decreases vs) | let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 1042,
"start_col": 0,
"start_line": 1038
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat ->
vs: Prims.list FStar.Stubs.Reflection.V2.Data.var ->
t: FStar.Stubs.Reflection.Types.term
-> Prims.Tot FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total",
""
] | [] | [
"Prims.nat",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.subst_term",
"FStar.Reflection.Typing.__close_term_vs",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Reflection.Typing.subst_elt",
"FStar.Reflection.Typing.ND",
"Prims.Nil"
] | [
"recursion"
] | false | false | false | true | false | let rec __close_term_vs (i: nat) (vs: list var) (t: term) : Tot term (decreases vs) =
| match vs with
| [] -> t
| v :: vs -> subst_term (__close_term_vs (i + 1) vs t) [ND v i] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.fstar_env_fvs | val fstar_env_fvs : g: FStar.Stubs.Reflection.Types.env -> Prims.logical | let fstar_env_fvs (g:R.env) =
lookup_fvar g unit_fv == Some (tm_type u_zero) /\
lookup_fvar g bool_fv == Some (tm_type u_zero) /\
lookup_fvar g b2t_fv == Some b2t_ty | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 1741,
"start_col": 0,
"start_line": 1738
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br)
let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs
let binding_to_namedv (b:R.binding) : Tot namedv =
pack_namedv {
RD.uniq = b.uniq;
RD.sort = seal b.sort;
RD.ppname = b.ppname;
}
(* Elaborates the p pattern into a term, using the bs bindings for the
pattern variables. The resulting term is properly scoped only on an
environment which contains all of bs. See for instance the branch_typing
judg. Returns an option, since this can fail if e.g. there are not
enough bindings, and returns the list of unused binders as well, which
should be empty if the list of binding was indeed ok. *)
let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) =
match p, bs with
| Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs)
| Pat_Cons fv univs subpats, bs ->
let head = pack_ln (Tv_FVar fv) in
fold_left_dec
(Some (head, bs))
subpats
(fun st pi ->
let (p,i) = pi in
match st with | None -> None | Some (head, bs) ->
match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs'))
| Pat_Var _ _, b::bs ->
Some (pack_ln (Tv_Var (binding_to_namedv b)), bs)
| Pat_Dot_Term (Some t), _ -> Some (t, bs)
| Pat_Dot_Term None, _ -> None
| _ -> None
[@@ no_auto_projectors]
noeq
type typing : env -> term -> comp_typ -> Type0 =
| T_Token :
g:env ->
e:term ->
c:comp_typ ->
squash (T.typing_token g e c) ->
typing g e c
| T_Var :
g:env ->
x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } ->
typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x)))
| T_FVar :
g:env ->
x:fv { Some? (lookup_fvar g x) } ->
typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x))
| T_UInst :
g:env ->
x:fv ->
us:list universe { Some? (lookup_fvar_uinst g x us) } ->
typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us))
| T_Const:
g:env ->
v:vconst ->
t:term ->
constant_typing v t ->
typing g (constant_as_term v) (T.E_Total, t)
| T_Abs :
g:env ->
x:var { None? (lookup_bvar g x) } ->
ty:term ->
body:term { ~(x `Set.mem` freevars body) } ->
body_c:comp_typ ->
u:universe ->
pp_name:pp_name_t ->
q:aqualv ->
ty_eff:T.tot_or_ghost ->
typing g ty (ty_eff, tm_type u) ->
typing (extend_env g x ty) (open_term body x) body_c ->
typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body))
(T.E_Total,
pack_ln (Tv_Arrow (mk_binder pp_name ty q)
(mk_comp (close_comp_typ body_c x))))
| T_App :
g:env ->
e1:term ->
e2:term ->
x:binder ->
t:term ->
eff:T.tot_or_ghost ->
typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) ->
typing g e2 (eff, binder_sort x) ->
typing g (pack_ln (Tv_App e1 (e2, binder_qual x)))
(eff, open_with t e2)
| T_Let:
g:env ->
x:var { None? (lookup_bvar g x) } ->
e1:term ->
t1:typ ->
e2:term ->
t2:typ ->
eff:T.tot_or_ghost ->
pp_name:pp_name_t ->
typing g e1 (eff, t1) ->
typing (extend_env g x t1) (open_term e2 x) (eff, t2) ->
typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1)
| T_Arrow:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t1:term ->
t2:term { ~(x `Set.mem` freevars t2) } ->
u1:universe ->
u2:universe ->
pp_name:pp_name_t ->
q:aqualv ->
eff:T.tot_or_ghost ->
t1_eff:T.tot_or_ghost ->
t2_eff:T.tot_or_ghost ->
typing g t1 (t1_eff, tm_type u1) ->
typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) ->
typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2))))
(T.E_Total, tm_type (u_max u1 u2))
| T_Refine:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t:term ->
e:term { ~(x `Set.mem` freevars e) } ->
u1:universe ->
u2:universe ->
t_eff:T.tot_or_ghost ->
e_eff:T.tot_or_ghost ->
typing g t (t_eff, tm_type u1) ->
typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) ->
typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1)
| T_PropIrrelevance:
g:env ->
e:term ->
t:term ->
e_eff:T.tot_or_ghost ->
t_eff:T.tot_or_ghost ->
typing g e (e_eff, t) ->
typing g t (t_eff, tm_prop) ->
typing g (`()) (T.E_Total, t)
| T_Sub:
g:env ->
e:term ->
c:comp_typ ->
c':comp_typ ->
typing g e c ->
sub_comp g c c' ->
typing g e c'
| T_If:
g:env ->
scrutinee:term ->
then_:term ->
else_:term ->
ty:term ->
u_ty:universe ->
hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } ->
eff:T.tot_or_ghost ->
ty_eff:T.tot_or_ghost ->
typing g scrutinee (eff, bool_ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) ->
typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp
typing g (mk_if scrutinee then_ else_) (eff, ty)
| T_Match:
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc : term ->
ty_eff:T.tot_or_ghost ->
typing g sc_ty (ty_eff, tm_type sc_u) ->
eff:T.tot_or_ghost ->
typing g sc (eff, sc_ty) ->
branches:list branch ->
ty:comp_typ ->
bnds:list (list R.binding) ->
complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns
branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type
typing g (pack_ln (Tv_Match sc None branches)) ty
and related : env -> term -> relation -> term -> Type0 =
| Rel_refl:
g:env ->
t:term ->
rel:relation ->
related g t rel t
| Rel_sym:
g:env ->
t0:term ->
t1:term ->
related g t0 R_Eq t1 ->
related g t1 R_Eq t0
| Rel_trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
rel:relation ->
related g t0 rel t1 ->
related g t1 rel t2 ->
related g t0 rel t2
| Rel_univ:
g:env ->
u:universe ->
v:universe ->
univ_eq u v ->
related g (tm_type u) R_Eq (tm_type v)
| Rel_beta:
g:env ->
t:typ ->
q:aqualv ->
e:term { ln' e 0 } ->
arg:term { ln arg } ->
related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q)))
R_Eq
(subst_term e [ DT 0 arg ])
| Rel_eq_token:
g:env ->
t0:term ->
t1:term ->
squash (T.equiv_token g t0 t1) ->
related g t0 R_Eq t1
| Rel_subtyping_token:
g:env ->
t0:term ->
t1:term ->
squash (T.subtyping_token g t0 t1) ->
related g t0 R_Sub t1
| Rel_equiv:
g:env ->
t0:term ->
t1:term ->
rel:relation ->
related g t0 R_Eq t1 ->
related g t0 rel t1
| Rel_arrow:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
c1:comp_typ ->
c2:comp_typ ->
rel:relation ->
x:var{
None? (lookup_bvar g x) /\
~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2))
} ->
related g t2 rel t1 ->
related_comp (extend_env g x t2)
(open_comp_typ c1 x)
rel
(open_comp_typ c2 x) ->
related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2)
| Rel_abs:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
e1:term ->
e2:term ->
x:var{
None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2))
} ->
related g t1 R_Eq t2 ->
related (extend_env g x t1)
(subst_term e1 (open_with_var x 0))
R_Eq
(subst_term e2 (open_with_var x 0)) ->
related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2)
| Rel_ctxt:
g:env ->
t0:term ->
t1:term ->
ctxt:term_ctxt ->
related g t0 R_Eq t1 ->
related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1)
and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 =
| Relc_typ:
g:env ->
t0:term ->
t1:term ->
eff:T.tot_or_ghost ->
rel:relation ->
related g t0 rel t1 ->
related_comp g (eff, t0) rel (eff, t1)
| Relc_total_ghost:
g:env ->
t:term ->
related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t)
| Relc_ghost_total:
g:env ->
t:term ->
non_informative g t ->
related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t)
and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (brs:list branch) -> (bnds : list (list R.binding)) -> Type0
=
(* This judgement only enforces that branch_typing holds for every
element of brs and its respective bnds (which must have the same
length). *)
| BT_Nil :
branches_typing g sc_u sc_ty sc rty [] []
| BT_S :
br : branch ->
bnds : list R.binding ->
pf : branch_typing g sc_u sc_ty sc rty br bnds ->
rest_br : list branch ->
rest_bnds : list (list R.binding) ->
rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds ->
branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds)
and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (br : branch) -> (bnds : list R.binding) -> Type0
=
| BO :
pat : pattern ->
bnds : list R.binding{bindings_ok_for_pat g bnds pat} ->
hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} ->
body:term ->
_ : squash (Some? (elaborate_pat pat bnds)) ->
typing (extend_env
(extend_env_l g (refl_bindings_to_bindings bnds))
hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds))))
)
body rty ->
branch_typing g sc_u sc_ty sc rty
(pat, close_term_bs (refl_bindings_to_bindings bnds) body)
bnds
and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 =
| MC_Tok :
env:_ ->
sc:_ ->
ty:_ ->
pats:_ ->
bnds:_ ->
squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds
and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2
and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2
and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2
type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t)
type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t)
val subtyping_token_renaming (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0))
(rename t0 x y)
(rename t1 x y)
val subtyping_token_weakening (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1
let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe)
(d:typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u)
= let ue
: univ_eq (u_max u u) u
= UN_MaxLeq u u (UNLEQ_Refl u)
in
let du : related g (tm_type (u_max u u)) R_Eq (tm_type u)
= Rel_univ g (u_max u u) u ue in
let du : related g (tm_type (u_max u u)) R_Sub (tm_type u)
= Rel_equiv _ _ _ _ du in
T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du)
val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: Lemma (ensures ln e /\ ln (snd c))
val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u))
val binder_offset_pattern_invariant (p:pattern) (ss:subst)
: Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss))
val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst)
: Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss))
val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var)
: Lemma
(ensures subst_term
(subst_term t [ ND x i ])
(open_with_var x i)
== t)
val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var)
: Lemma (ensures subst_binder
(subst_binder b [ ND x i ])
(open_with_var x i)
== b)
val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var)
: Lemma (ensures subst_terms
(subst_terms ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var)
: Lemma
(ensures subst_comp
(subst_comp c [ ND x i ])
(open_with_var x i)
== c)
val open_close_inverse'_args (i:nat)
(ts:list argv { ln'_args ts (i - 1) })
(x:var)
: Lemma
(ensures subst_args
(subst_args ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_patterns (i:nat)
(ps:list (pattern & bool) { ln'_patterns ps (i - 1) })
(x:var)
: Lemma
(ensures subst_patterns
(subst_patterns ps [ ND x i ])
(open_with_var x i)
== ps)
val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var)
: Lemma
(ensures subst_pattern
(subst_pattern p [ ND x i ])
(open_with_var x i)
== p)
val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var)
: Lemma
(ensures subst_branch
(subst_branch br [ ND x i ])
(open_with_var x i)
== br)
val open_close_inverse'_branches (i:nat)
(brs:list branch { ln'_branches brs (i - 1) })
(x:var)
: Lemma
(ensures subst_branches
(subst_branches brs [ ND x i ])
(open_with_var x i)
== brs)
val open_close_inverse'_match_returns (i:nat)
(m:match_returns_ascription { ln'_match_returns m (i - 1) })
(x:var)
: Lemma
(ensures subst_match_returns
(subst_match_returns m [ ND x i ])
(open_with_var x i)
== m)
val open_close_inverse (e:R.term { ln e }) (x:var)
: Lemma (open_term (close_term e x) x == e)
val close_open_inverse' (i:nat)
(t:term)
(x:var { ~(x `Set.mem` freevars t) })
: Lemma
(ensures subst_term
(subst_term t (open_with_var x i))
[ ND x i ]
== t)
val close_open_inverse'_comp (i:nat)
(c:comp)
(x:var{ ~(x `Set.mem` freevars_comp c) })
: Lemma
(ensures subst_comp
(subst_comp c (open_with_var x i))
[ ND x i ]
== c)
val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) })
: Lemma
(ensures subst_args
(subst_args args (open_with_var x i))
[ ND x i]
== args)
val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) })
: Lemma
(ensures subst_binder
(subst_binder b (open_with_var x i))
[ ND x i ]
== b)
val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) })
: Lemma
(ensures subst_terms
(subst_terms ts (open_with_var x i))
[ ND x i ]
== ts)
val close_open_inverse'_branches (i:nat) (brs:list branch)
(x:var{ ~(x `Set.mem` freevars_branches brs) })
: Lemma
(ensures subst_branches
(subst_branches brs (open_with_var x i))
[ ND x i ]
== brs)
val close_open_inverse'_branch (i:nat)
(br:branch)
(x:var{ ~(x `Set.mem` freevars_branch br) })
: Lemma
(ensures subst_branch
(subst_branch br (open_with_var x i))
[ ND x i ]
== br)
val close_open_inverse'_pattern (i:nat)
(p:pattern)
(x:var{ ~(x `Set.mem` freevars_pattern p) })
: Lemma
(ensures subst_pattern
(subst_pattern p (open_with_var x i))
[ ND x i ]
== p)
val close_open_inverse'_patterns (i:nat)
(ps:list (pattern & bool))
(x:var {~ (x `Set.mem` freevars_patterns ps) })
: Lemma
(ensures subst_patterns
(subst_patterns ps (open_with_var x i))
[ ND x i ]
== ps)
val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription)
(x:var{ ~(x `Set.mem` freevars_match_returns m) })
: Lemma
(ensures subst_match_returns
(subst_match_returns m (open_with_var x i))
[ ND x i ]
== m)
val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) })
: Lemma (close_term (open_term e x) x == e)
//
// fst has corresponding lemmas for other syntax classes
//
val close_with_not_free_var (t:R.term) (x:var) (i:nat)
: Lemma
(requires ~ (Set.mem x (freevars t)))
(ensures subst_term t [ ND x i ] == t)
// this also requires x to be not in freevars e1 `Set.union` freevars e2
val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var { None? (lookup_bvar g x) })
(eq:equiv (extend_env g x ty)
(subst_term e1 (open_with_var x 0))
(subst_term e2 (open_with_var x 0)))
: equiv g (mk_arrow ty q e1)
(mk_arrow ty q e2)
// the proof for this requires e1 and e2 to be ln
val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var{None? (lookup_bvar g x)})
(eq:equiv (extend_env g x ty) e1 e2)
: equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ]))
(mk_abs ty q (subst_term e2 [ ND x 0 ]))
val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat)
: Lemma
(requires ln' e i /\ i < j)
(ensures subst_term e [ DT j t ] == e)
[SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])]
//
// Type of the top-level tactic that would splice-in the definitions
// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: FStar.Stubs.Reflection.Types.env -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.lookup_fvar",
"FStar.Reflection.Typing.unit_fv",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.tm_type",
"FStar.Reflection.Typing.u_zero",
"FStar.Reflection.Typing.bool_fv",
"FStar.Reflection.Typing.b2t_fv",
"FStar.Reflection.Typing.b2t_ty",
"Prims.logical"
] | [] | false | false | false | true | true | let fstar_env_fvs (g: R.env) =
| lookup_fvar g unit_fv == Some (tm_type u_zero) /\ lookup_fvar g bool_fv == Some (tm_type u_zero) /\
lookup_fvar g b2t_fv == Some b2t_ty | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.extend_env_l | val extend_env_l (g: env) (bs: bindings) : env | val extend_env_l (g: env) (bs: bindings) : env | let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 1025,
"start_col": 0,
"start_line": 1021
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: FStar.Stubs.Reflection.Types.env -> bs: FStar.Reflection.Typing.bindings
-> FStar.Stubs.Reflection.Types.env | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"FStar.Reflection.Typing.bindings",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.Typing.binding",
"FStar.Reflection.Typing.extend_env",
"FStar.Reflection.Typing.extend_env_l"
] | [
"recursion"
] | false | false | false | true | false | let rec extend_env_l (g: env) (bs: bindings) : env =
| match bs with
| [] -> g
| (x, t) :: bs -> extend_env (extend_env_l g bs) x t | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.is_non_informative_name | val is_non_informative_name (l: name) : bool | val is_non_informative_name (l: name) : bool | let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"] | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 1033,
"start_col": 0,
"start_line": 1030
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: FStar.Stubs.Reflection.Types.name -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.name",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"FStar.Reflection.Const.unit_lid",
"FStar.Reflection.Const.squash_qn",
"Prims.Cons",
"Prims.Nil",
"Prims.bool"
] | [] | false | false | false | true | false | let is_non_informative_name (l: name) : bool =
| l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] | false |
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.sigelt_for | val sigelt_for : g: FStar.Stubs.Reflection.Types.env -> Type0 | let sigelt_for (g:env) =
tup:(bool & sigelt & option blob)
{
let (checked, se, _) = tup in
checked ==> sigelt_typing g se
} | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 1801,
"start_col": 0,
"start_line": 1796
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br)
let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs
let binding_to_namedv (b:R.binding) : Tot namedv =
pack_namedv {
RD.uniq = b.uniq;
RD.sort = seal b.sort;
RD.ppname = b.ppname;
}
(* Elaborates the p pattern into a term, using the bs bindings for the
pattern variables. The resulting term is properly scoped only on an
environment which contains all of bs. See for instance the branch_typing
judg. Returns an option, since this can fail if e.g. there are not
enough bindings, and returns the list of unused binders as well, which
should be empty if the list of binding was indeed ok. *)
let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) =
match p, bs with
| Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs)
| Pat_Cons fv univs subpats, bs ->
let head = pack_ln (Tv_FVar fv) in
fold_left_dec
(Some (head, bs))
subpats
(fun st pi ->
let (p,i) = pi in
match st with | None -> None | Some (head, bs) ->
match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs'))
| Pat_Var _ _, b::bs ->
Some (pack_ln (Tv_Var (binding_to_namedv b)), bs)
| Pat_Dot_Term (Some t), _ -> Some (t, bs)
| Pat_Dot_Term None, _ -> None
| _ -> None
[@@ no_auto_projectors]
noeq
type typing : env -> term -> comp_typ -> Type0 =
| T_Token :
g:env ->
e:term ->
c:comp_typ ->
squash (T.typing_token g e c) ->
typing g e c
| T_Var :
g:env ->
x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } ->
typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x)))
| T_FVar :
g:env ->
x:fv { Some? (lookup_fvar g x) } ->
typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x))
| T_UInst :
g:env ->
x:fv ->
us:list universe { Some? (lookup_fvar_uinst g x us) } ->
typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us))
| T_Const:
g:env ->
v:vconst ->
t:term ->
constant_typing v t ->
typing g (constant_as_term v) (T.E_Total, t)
| T_Abs :
g:env ->
x:var { None? (lookup_bvar g x) } ->
ty:term ->
body:term { ~(x `Set.mem` freevars body) } ->
body_c:comp_typ ->
u:universe ->
pp_name:pp_name_t ->
q:aqualv ->
ty_eff:T.tot_or_ghost ->
typing g ty (ty_eff, tm_type u) ->
typing (extend_env g x ty) (open_term body x) body_c ->
typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body))
(T.E_Total,
pack_ln (Tv_Arrow (mk_binder pp_name ty q)
(mk_comp (close_comp_typ body_c x))))
| T_App :
g:env ->
e1:term ->
e2:term ->
x:binder ->
t:term ->
eff:T.tot_or_ghost ->
typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) ->
typing g e2 (eff, binder_sort x) ->
typing g (pack_ln (Tv_App e1 (e2, binder_qual x)))
(eff, open_with t e2)
| T_Let:
g:env ->
x:var { None? (lookup_bvar g x) } ->
e1:term ->
t1:typ ->
e2:term ->
t2:typ ->
eff:T.tot_or_ghost ->
pp_name:pp_name_t ->
typing g e1 (eff, t1) ->
typing (extend_env g x t1) (open_term e2 x) (eff, t2) ->
typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1)
| T_Arrow:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t1:term ->
t2:term { ~(x `Set.mem` freevars t2) } ->
u1:universe ->
u2:universe ->
pp_name:pp_name_t ->
q:aqualv ->
eff:T.tot_or_ghost ->
t1_eff:T.tot_or_ghost ->
t2_eff:T.tot_or_ghost ->
typing g t1 (t1_eff, tm_type u1) ->
typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) ->
typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2))))
(T.E_Total, tm_type (u_max u1 u2))
| T_Refine:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t:term ->
e:term { ~(x `Set.mem` freevars e) } ->
u1:universe ->
u2:universe ->
t_eff:T.tot_or_ghost ->
e_eff:T.tot_or_ghost ->
typing g t (t_eff, tm_type u1) ->
typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) ->
typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1)
| T_PropIrrelevance:
g:env ->
e:term ->
t:term ->
e_eff:T.tot_or_ghost ->
t_eff:T.tot_or_ghost ->
typing g e (e_eff, t) ->
typing g t (t_eff, tm_prop) ->
typing g (`()) (T.E_Total, t)
| T_Sub:
g:env ->
e:term ->
c:comp_typ ->
c':comp_typ ->
typing g e c ->
sub_comp g c c' ->
typing g e c'
| T_If:
g:env ->
scrutinee:term ->
then_:term ->
else_:term ->
ty:term ->
u_ty:universe ->
hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } ->
eff:T.tot_or_ghost ->
ty_eff:T.tot_or_ghost ->
typing g scrutinee (eff, bool_ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) ->
typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp
typing g (mk_if scrutinee then_ else_) (eff, ty)
| T_Match:
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc : term ->
ty_eff:T.tot_or_ghost ->
typing g sc_ty (ty_eff, tm_type sc_u) ->
eff:T.tot_or_ghost ->
typing g sc (eff, sc_ty) ->
branches:list branch ->
ty:comp_typ ->
bnds:list (list R.binding) ->
complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns
branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type
typing g (pack_ln (Tv_Match sc None branches)) ty
and related : env -> term -> relation -> term -> Type0 =
| Rel_refl:
g:env ->
t:term ->
rel:relation ->
related g t rel t
| Rel_sym:
g:env ->
t0:term ->
t1:term ->
related g t0 R_Eq t1 ->
related g t1 R_Eq t0
| Rel_trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
rel:relation ->
related g t0 rel t1 ->
related g t1 rel t2 ->
related g t0 rel t2
| Rel_univ:
g:env ->
u:universe ->
v:universe ->
univ_eq u v ->
related g (tm_type u) R_Eq (tm_type v)
| Rel_beta:
g:env ->
t:typ ->
q:aqualv ->
e:term { ln' e 0 } ->
arg:term { ln arg } ->
related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q)))
R_Eq
(subst_term e [ DT 0 arg ])
| Rel_eq_token:
g:env ->
t0:term ->
t1:term ->
squash (T.equiv_token g t0 t1) ->
related g t0 R_Eq t1
| Rel_subtyping_token:
g:env ->
t0:term ->
t1:term ->
squash (T.subtyping_token g t0 t1) ->
related g t0 R_Sub t1
| Rel_equiv:
g:env ->
t0:term ->
t1:term ->
rel:relation ->
related g t0 R_Eq t1 ->
related g t0 rel t1
| Rel_arrow:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
c1:comp_typ ->
c2:comp_typ ->
rel:relation ->
x:var{
None? (lookup_bvar g x) /\
~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2))
} ->
related g t2 rel t1 ->
related_comp (extend_env g x t2)
(open_comp_typ c1 x)
rel
(open_comp_typ c2 x) ->
related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2)
| Rel_abs:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
e1:term ->
e2:term ->
x:var{
None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2))
} ->
related g t1 R_Eq t2 ->
related (extend_env g x t1)
(subst_term e1 (open_with_var x 0))
R_Eq
(subst_term e2 (open_with_var x 0)) ->
related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2)
| Rel_ctxt:
g:env ->
t0:term ->
t1:term ->
ctxt:term_ctxt ->
related g t0 R_Eq t1 ->
related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1)
and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 =
| Relc_typ:
g:env ->
t0:term ->
t1:term ->
eff:T.tot_or_ghost ->
rel:relation ->
related g t0 rel t1 ->
related_comp g (eff, t0) rel (eff, t1)
| Relc_total_ghost:
g:env ->
t:term ->
related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t)
| Relc_ghost_total:
g:env ->
t:term ->
non_informative g t ->
related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t)
and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (brs:list branch) -> (bnds : list (list R.binding)) -> Type0
=
(* This judgement only enforces that branch_typing holds for every
element of brs and its respective bnds (which must have the same
length). *)
| BT_Nil :
branches_typing g sc_u sc_ty sc rty [] []
| BT_S :
br : branch ->
bnds : list R.binding ->
pf : branch_typing g sc_u sc_ty sc rty br bnds ->
rest_br : list branch ->
rest_bnds : list (list R.binding) ->
rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds ->
branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds)
and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (br : branch) -> (bnds : list R.binding) -> Type0
=
| BO :
pat : pattern ->
bnds : list R.binding{bindings_ok_for_pat g bnds pat} ->
hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} ->
body:term ->
_ : squash (Some? (elaborate_pat pat bnds)) ->
typing (extend_env
(extend_env_l g (refl_bindings_to_bindings bnds))
hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds))))
)
body rty ->
branch_typing g sc_u sc_ty sc rty
(pat, close_term_bs (refl_bindings_to_bindings bnds) body)
bnds
and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 =
| MC_Tok :
env:_ ->
sc:_ ->
ty:_ ->
pats:_ ->
bnds:_ ->
squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds
and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2
and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2
and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2
type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t)
type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t)
val subtyping_token_renaming (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0))
(rename t0 x y)
(rename t1 x y)
val subtyping_token_weakening (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1
let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe)
(d:typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u)
= let ue
: univ_eq (u_max u u) u
= UN_MaxLeq u u (UNLEQ_Refl u)
in
let du : related g (tm_type (u_max u u)) R_Eq (tm_type u)
= Rel_univ g (u_max u u) u ue in
let du : related g (tm_type (u_max u u)) R_Sub (tm_type u)
= Rel_equiv _ _ _ _ du in
T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du)
val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: Lemma (ensures ln e /\ ln (snd c))
val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u))
val binder_offset_pattern_invariant (p:pattern) (ss:subst)
: Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss))
val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst)
: Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss))
val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var)
: Lemma
(ensures subst_term
(subst_term t [ ND x i ])
(open_with_var x i)
== t)
val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var)
: Lemma (ensures subst_binder
(subst_binder b [ ND x i ])
(open_with_var x i)
== b)
val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var)
: Lemma (ensures subst_terms
(subst_terms ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var)
: Lemma
(ensures subst_comp
(subst_comp c [ ND x i ])
(open_with_var x i)
== c)
val open_close_inverse'_args (i:nat)
(ts:list argv { ln'_args ts (i - 1) })
(x:var)
: Lemma
(ensures subst_args
(subst_args ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_patterns (i:nat)
(ps:list (pattern & bool) { ln'_patterns ps (i - 1) })
(x:var)
: Lemma
(ensures subst_patterns
(subst_patterns ps [ ND x i ])
(open_with_var x i)
== ps)
val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var)
: Lemma
(ensures subst_pattern
(subst_pattern p [ ND x i ])
(open_with_var x i)
== p)
val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var)
: Lemma
(ensures subst_branch
(subst_branch br [ ND x i ])
(open_with_var x i)
== br)
val open_close_inverse'_branches (i:nat)
(brs:list branch { ln'_branches brs (i - 1) })
(x:var)
: Lemma
(ensures subst_branches
(subst_branches brs [ ND x i ])
(open_with_var x i)
== brs)
val open_close_inverse'_match_returns (i:nat)
(m:match_returns_ascription { ln'_match_returns m (i - 1) })
(x:var)
: Lemma
(ensures subst_match_returns
(subst_match_returns m [ ND x i ])
(open_with_var x i)
== m)
val open_close_inverse (e:R.term { ln e }) (x:var)
: Lemma (open_term (close_term e x) x == e)
val close_open_inverse' (i:nat)
(t:term)
(x:var { ~(x `Set.mem` freevars t) })
: Lemma
(ensures subst_term
(subst_term t (open_with_var x i))
[ ND x i ]
== t)
val close_open_inverse'_comp (i:nat)
(c:comp)
(x:var{ ~(x `Set.mem` freevars_comp c) })
: Lemma
(ensures subst_comp
(subst_comp c (open_with_var x i))
[ ND x i ]
== c)
val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) })
: Lemma
(ensures subst_args
(subst_args args (open_with_var x i))
[ ND x i]
== args)
val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) })
: Lemma
(ensures subst_binder
(subst_binder b (open_with_var x i))
[ ND x i ]
== b)
val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) })
: Lemma
(ensures subst_terms
(subst_terms ts (open_with_var x i))
[ ND x i ]
== ts)
val close_open_inverse'_branches (i:nat) (brs:list branch)
(x:var{ ~(x `Set.mem` freevars_branches brs) })
: Lemma
(ensures subst_branches
(subst_branches brs (open_with_var x i))
[ ND x i ]
== brs)
val close_open_inverse'_branch (i:nat)
(br:branch)
(x:var{ ~(x `Set.mem` freevars_branch br) })
: Lemma
(ensures subst_branch
(subst_branch br (open_with_var x i))
[ ND x i ]
== br)
val close_open_inverse'_pattern (i:nat)
(p:pattern)
(x:var{ ~(x `Set.mem` freevars_pattern p) })
: Lemma
(ensures subst_pattern
(subst_pattern p (open_with_var x i))
[ ND x i ]
== p)
val close_open_inverse'_patterns (i:nat)
(ps:list (pattern & bool))
(x:var {~ (x `Set.mem` freevars_patterns ps) })
: Lemma
(ensures subst_patterns
(subst_patterns ps (open_with_var x i))
[ ND x i ]
== ps)
val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription)
(x:var{ ~(x `Set.mem` freevars_match_returns m) })
: Lemma
(ensures subst_match_returns
(subst_match_returns m (open_with_var x i))
[ ND x i ]
== m)
val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) })
: Lemma (close_term (open_term e x) x == e)
//
// fst has corresponding lemmas for other syntax classes
//
val close_with_not_free_var (t:R.term) (x:var) (i:nat)
: Lemma
(requires ~ (Set.mem x (freevars t)))
(ensures subst_term t [ ND x i ] == t)
// this also requires x to be not in freevars e1 `Set.union` freevars e2
val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var { None? (lookup_bvar g x) })
(eq:equiv (extend_env g x ty)
(subst_term e1 (open_with_var x 0))
(subst_term e2 (open_with_var x 0)))
: equiv g (mk_arrow ty q e1)
(mk_arrow ty q e2)
// the proof for this requires e1 and e2 to be ln
val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var{None? (lookup_bvar g x)})
(eq:equiv (extend_env g x ty) e1 e2)
: equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ]))
(mk_abs ty q (subst_term e2 [ ND x 0 ]))
val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat)
: Lemma
(requires ln' e i /\ i < j)
(ensures subst_term e [ DT j t ] == e)
[SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])]
//
// Type of the top-level tactic that would splice-in the definitions
//
let fstar_env_fvs (g:R.env) =
lookup_fvar g unit_fv == Some (tm_type u_zero) /\
lookup_fvar g bool_fv == Some (tm_type u_zero) /\
lookup_fvar g b2t_fv == Some b2t_ty
type fstar_env = g:R.env{fstar_env_fvs g}
type fstar_top_env = g:fstar_env {
forall x. None? (lookup_bvar g x )
}
//
// This doesn't allow for universe polymorphic definitions
//
// May be we can change it to:
//
// g:fstar_top_env -> T.tac ((us, e, t):(univ_names & term & typ){typing (push g us) e t})
//
noeq
type sigelt_typing : env -> sigelt -> Type0 =
| ST_Let :
g : env ->
fv : R.fv ->
ty : R.typ ->
tm : R.term ->
squash (typing g tm (T.E_Total, ty)) ->
sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm })]))
| ST_Let_Opaque :
g : env ->
fv : R.fv ->
ty : R.typ ->
(* no tm: only a proof of existence *)
squash (exists (tm:R.term). typing g tm (T.E_Total, ty)) ->
sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) })]))
(**
* The type of the top-level tactic that would splice-in the definitions.
* It returns a list of well typed definitions, via the judgment above.
*
* Each definition can have a 'blob' attached with a given name.
* The blob can be used later, e.g., during extraction, and passed back to the
* extension to perform additional processing.
*)
(*
* It returns either:
* - Some tm, blob, typ, with a proof that `typing g tm typ`
* - None, blob, typ), with a proof that `exists tm. typing g tm typ`
* The blob itself is optional and can store some additional metadata that
* constructed by the tactic. If present, it will be stored in the
* sigmeta_extension_data field of the enclosing sigelt.
*
*)
let blob = string & R.term
(* If checked is true, this sigelt is properly typed for the environment. If not, | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: FStar.Stubs.Reflection.Types.env -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"FStar.Pervasives.Native.tuple3",
"Prims.bool",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Typing.blob",
"Prims.l_imp",
"Prims.b2t",
"FStar.Reflection.Typing.sigelt_typing"
] | [] | false | false | false | true | true | let sigelt_for (g: env) =
| tup:
(bool & sigelt & option blob)
{ let checked, se, _ = tup in
checked ==> sigelt_typing g se } | false |
|
FStar.Reflection.Typing.fsti | FStar.Reflection.Typing.dsl_tac_result_t | val dsl_tac_result_t : g: FStar.Stubs.Reflection.Types.env -> Type0 | let dsl_tac_result_t (g:env) = list (sigelt_for g) | {
"file_name": "ulib/experimental/FStar.Reflection.Typing.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 1803,
"start_col": 0,
"start_line": 1803
} | (*
Copyright 2008-2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.Typing
(** This module defines a typing judgment for (parts of) the total
and ghost fragment of F*.
We are using it in the meta DSL framework as an
official specification for the F* type system.
We expect it to grow to cover more of the F* language.
IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE.
*)
open FStar.List.Tot
open FStar.Reflection.V2
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module T = FStar.Tactics.V2
module RD = FStar.Stubs.Reflection.V2.Data
(* MOVE to some helper module *)
let rec fold_left_dec #a #b
(acc : a)
(l : list b)
(f : a -> (x:b{x << l}) -> a)
: Tot a (decreases l)
=
match l with
| [] -> acc
| x::xs -> fold_left_dec (f acc x) xs f
let rec map_dec #a #b
(l : list a)
(f : (x:a{x << l}) -> b)
: Tot (list b) (decreases l)
=
match l with
| [] -> []
| x::xs -> f x :: map_dec xs f
let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 =
match xs, ys with
| [], [] -> True
| x::xx, y::yy -> f x y /\ zip2prop f xx yy
| _ -> False
(* / MOVE *)
val inspect_pack (t:R.term_view)
: Lemma (ensures R.(inspect_ln (pack_ln t) == t))
[SMTPat R.(inspect_ln (pack_ln t))]
val pack_inspect (t:R.term)
: Lemma (requires ~(Tv_Unsupp? (inspect_ln t)))
(ensures R.(pack_ln (inspect_ln t) == t))
[SMTPat R.(pack_ln (inspect_ln t))]
val inspect_pack_namedv (t:R.namedv_view)
: Lemma (ensures R.(inspect_namedv (pack_namedv t) == t))
[SMTPat R.(inspect_namedv (pack_namedv t))]
val pack_inspect_namedv (t:R.namedv)
: Lemma (ensures R.(pack_namedv (inspect_namedv t) == t))
[SMTPat R.(pack_namedv (inspect_namedv t))]
val inspect_pack_bv (t:R.bv_view)
: Lemma (ensures R.(inspect_bv (pack_bv t) == t))
[SMTPat R.(inspect_bv (pack_bv t))]
val pack_inspect_bv (t:R.bv)
: Lemma (ensures R.(pack_bv (inspect_bv t) == t))
[SMTPat R.(pack_bv (inspect_bv t))]
val inspect_pack_binder (bview:R.binder_view)
: Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview))
[SMTPat R.(inspect_binder (pack_binder bview))]
val pack_inspect_binder (t:R.binder)
: Lemma (ensures (R.pack_binder (R.inspect_binder t) == t))
[SMTPat (R.pack_binder (R.inspect_binder t))]
val inspect_pack_comp (t:R.comp_view)
: Lemma (ensures (R.inspect_comp (R.pack_comp t) == t))
[SMTPat (R.inspect_comp (R.pack_comp t))]
val pack_inspect_comp (t:R.comp)
: Lemma (ensures (R.pack_comp (R.inspect_comp t) == t))
[SMTPat (R.pack_comp (R.inspect_comp t))]
val inspect_pack_fv (nm:R.name)
: Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm)
[SMTPat (R.inspect_fv (R.pack_fv nm))]
val pack_inspect_fv (fv:R.fv)
: Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv)
[SMTPat (R.pack_fv (R.inspect_fv fv))]
val inspect_pack_universe (u:R.universe_view)
: Lemma (ensures R.inspect_universe (R.pack_universe u) == u)
[SMTPat (R.inspect_universe (R.pack_universe u))]
val pack_inspect_universe (u:R.universe)
: Lemma (requires ~(Uv_Unk? (inspect_universe u)))
(ensures R.pack_universe (R.inspect_universe u) == u)
[SMTPat (R.pack_universe (R.inspect_universe u))]
val lookup_bvar (e:env) (x:int) : option term
val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term
let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x []
let pp_name_t = FStar.Sealed.Inhabited.sealed "x"
let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x"
let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x
let tun = pack_ln Tv_Unknown
let sort_t = FStar.Sealed.Inhabited.sealed tun
let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun
let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x
let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder
= pack_binder
{ ppname = pp_name;
qual = q;
attrs = [];
sort = ty}
let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder
= pack_binder
{ ppname = pp_name;
qual = Q_Explicit;
attrs = [];
sort = ty}
let extend_env (e:env) (x:var) (ty:term) : env =
R.push_binding e ({
ppname = seal_pp_name "x";
uniq = x;
sort = ty;
})
val lookup_bvar_extend_env (g:env) (x y:var) (ty:term)
: Lemma
(ensures (
if x = y
then lookup_bvar (extend_env g x ty) y == Some ty
else lookup_bvar (extend_env g x ty) y == lookup_bvar g y))
[SMTPat (lookup_bvar (extend_env g x ty) y)]
val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term)
: Lemma
(ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us)
[SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)]
let bv_index (x:bv)
: var
= (inspect_bv x).index
let namedv_uniq (x:namedv)
: var
= (inspect_namedv x).uniq
let binder_sort (b:binder) =
(inspect_binder b).sort
let binder_qual (b:binder) =
let { qual = q } = inspect_binder b in q
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let maybe_uniq_of_term (x:term) =
match inspect_ln x with
| Tv_Var namedv -> Some (namedv_uniq namedv)
| _ -> None
let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt =
match s with
| [] -> None
| (DT j t)::ss ->
if j = bv_index bv
then Some (DT j t)
else find_matching_subst_elt_bv ss bv
| _::ss -> find_matching_subst_elt_bv ss bv
let subst_db (bv:bv) (s:subst) : term =
match find_matching_subst_elt_bv s bv with
| Some (DT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
//if we're substituting a name j for a name k, retain the pp_name of j
let v : namedv = pack_namedv {
sort = (inspect_bv bv).sort;
ppname = (inspect_bv bv).ppname;
uniq = k;
} in
pack_ln (Tv_Var v))
| _ -> pack_ln (Tv_BVar bv)
let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt =
match s with
| [] -> None
| (NT y _)::rest
| (ND y _)::rest ->
if y = namedv_uniq v
then Some (L.hd s)
else find_matching_subst_elt_var rest v
| _::rest -> find_matching_subst_elt_var rest v
let subst_var (v:namedv) (s:subst) : term =
match find_matching_subst_elt_var s v with
| Some (NT _ t) ->
(match maybe_uniq_of_term t with
| None -> t
| Some k ->
pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k })))
| Some (ND _ i) ->
let bv = pack_bv {
sort = (inspect_namedv v).sort;
ppname = (inspect_namedv v).ppname;
index = i;
} in
pack_ln (Tv_BVar bv)
| _ -> pack_ln (Tv_Var v)
let make_bv (n:nat) : bv_view = {
ppname = pp_name_default;
index = n;
sort = sort_default;
}
let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = {
ppname = s;
index = n;
sort = sort_default;
}
let var_as_bv (v:nat) = pack_bv (make_bv v)
let make_namedv (n:nat) : namedv_view = {
ppname = pp_name_default;
uniq = n;
sort = sort_default;
}
let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = {
ppname = s;
uniq = n;
sort = sort_default;
}
let var_as_namedv (v:nat) : namedv =
pack_namedv {
uniq = v;
sort = sort_default;
ppname = pp_name_default;
}
let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v))
let binder_of_t_q t q = mk_binder pp_name_default t q
let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t)
let mk_total t = pack_comp (C_Total t)
let mk_ghost t = pack_comp (C_GTotal t)
let mk_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t))
let mk_ghost_arrow ty qual t : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t))
let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i)))
let mk_let ppname (e1 t1 e2:R.term) =
R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2)
let open_with_var_elt (x:var) (i:nat) : subst_elt =
DT i (pack_ln (Tv_Var (var_as_namedv x)))
let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i]
val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst)
: ctx_uvar_and_subst
let rec binder_offset_patterns (ps:list (pattern & bool))
: nat
= match ps with
| [] -> 0
| (p, b)::ps ->
let n = binder_offset_pattern p in
let m = binder_offset_patterns ps in
n + m
and binder_offset_pattern (p:pattern)
: nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ -> 0
| Pat_Var _ _ -> 1
| Pat_Cons head univs subpats ->
binder_offset_patterns subpats
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= match inspect_ln t with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unsupp
| Tv_Unknown -> t
| Tv_Var x -> subst_var x ss
| Tv_BVar j -> subst_db j ss
| Tv_App hd argv ->
pack_ln (Tv_App (subst_term hd ss)
(subst_term (fst argv) ss, snd argv))
| Tv_Abs b body ->
let b' = subst_binder b ss in
pack_ln (Tv_Abs b' (subst_term body (shift_subst ss)))
| Tv_Arrow b c ->
let b' = subst_binder b ss in
pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss)))
| Tv_Refine b f ->
let b = subst_binder b ss in
pack_ln (Tv_Refine b (subst_term f (shift_subst ss)))
| Tv_Uvar j c ->
pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss))
| Tv_Let recf attrs b def body ->
let b = subst_binder b ss in
pack_ln (Tv_Let recf
(subst_terms attrs ss)
b
(if recf
then subst_term def (shift_subst ss)
else subst_term def ss)
(subst_term body (shift_subst ss)))
| Tv_Match scr ret brs ->
pack_ln (Tv_Match (subst_term scr ss)
(match ret with
| None -> None
| Some m -> Some (subst_match_returns m ss))
(subst_branches brs ss))
| Tv_AscribedT e t tac b ->
pack_ln (Tv_AscribedT (subst_term e ss)
(subst_term t ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
| Tv_AscribedC e c tac b ->
pack_ln (Tv_AscribedC (subst_term e ss)
(subst_comp c ss)
(match tac with
| None -> None
| Some tac -> Some (subst_term tac ss))
b)
and subst_binder (b:binder) (ss:subst)
: Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b)
= let bndr = inspect_binder b in
pack_binder {
ppname = bndr.ppname;
qual = bndr.qual;
attrs = subst_terms bndr.attrs ss;
sort = subst_term bndr.sort ss
}
and subst_comp (c:comp) (ss:subst)
: Tot comp (decreases c)
= match inspect_comp c with
| C_Total t ->
pack_comp (C_Total (subst_term t ss))
| C_GTotal t ->
pack_comp (C_GTotal (subst_term t ss))
| C_Lemma pre post pats ->
pack_comp (C_Lemma (subst_term pre ss)
(subst_term post ss)
(subst_term pats ss))
| C_Eff us eff_name res args decrs ->
pack_comp (C_Eff us eff_name
(subst_term res ss)
(subst_args args ss)
(subst_terms decrs ss))
and subst_terms (ts:list term) (ss:subst)
: Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder
(decreases ts)
= match ts with
| [] -> []
| t::ts -> subst_term t ss :: subst_terms ts ss
and subst_args (ts:list argv) (ss:subst)
: Tot (list argv) (decreases ts)
= match ts with
| [] -> []
| (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss
and subst_patterns (ps:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool))
(decreases ps)
= match ps with
| [] -> ps
| (p, b)::ps ->
let n = binder_offset_pattern p in
let p = subst_pattern p ss in
let ps = subst_patterns ps (shift_subst_n n ss) in
(p,b)::ps
and subst_pattern (p:pattern) (ss:subst)
: Tot pattern
(decreases p)
= match p with
| Pat_Constant _ -> p
| Pat_Cons fv us pats ->
let pats = subst_patterns pats ss in
Pat_Cons fv us pats
| Pat_Var bv s ->
Pat_Var bv s
| Pat_Dot_Term topt ->
Pat_Dot_Term (match topt with
| None -> None
| Some t -> Some (subst_term t ss))
and subst_branch (br:branch) (ss:subst)
: Tot branch (decreases br)
= let p, t = br in
let p = subst_pattern p ss in
let j = binder_offset_pattern p in
let t = subst_term t (shift_subst_n j ss) in
p, t
and subst_branches (brs:list branch) (ss:subst)
: Tot (list branch) (decreases brs)
= match brs with
| [] -> []
| br::brs -> subst_branch br ss :: subst_branches brs ss
and subst_match_returns (m:match_returns_ascription) (ss:subst)
: Tot match_returns_ascription (decreases m)
= let b, (ret, as_, eq) = m in
let b = subst_binder b ss in
let ret =
match ret with
| Inl t -> Inl (subst_term t (shift_subst ss))
| Inr c -> Inr (subst_comp c (shift_subst ss))
in
let as_ =
match as_ with
| None -> None
| Some t -> Some (subst_term t (shift_subst ss))
in
b, (ret, as_, eq)
val open_with (t:term) (v:term) : term
val open_with_spec (t v:term)
: Lemma (open_with t v ==
subst_term t [ DT 0 v ])
val open_term (t:term) (v:var) : term
val open_term_spec (t:term) (v:var)
: Lemma (open_term t v ==
subst_term t (open_with_var v 0))
val close_term (t:term) (v:var) : term
val close_term_spec (t:term) (v:var)
: Lemma (close_term t v ==
subst_term t [ ND v 0 ])
val rename (t:term) (x y:var) : term
val rename_spec (t:term) (x y:var)
: Lemma (rename t x y ==
subst_term t [ NT x (var_as_term y)])
val bv_index_of_make_bv (n:nat)
: Lemma (ensures bv_index (pack_bv (make_bv n)) == n)
[SMTPat (bv_index (pack_bv (make_bv n)))]
val namedv_uniq_of_make_namedv (n:nat)
: Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n)
[SMTPat (namedv_uniq (pack_namedv (make_namedv n)))]
let constant_as_term (v:vconst) = pack_ln (Tv_Const v)
let unit_exp = constant_as_term C_Unit
let unit_fv = pack_fv unit_lid
let unit_ty = pack_ln (Tv_FVar unit_fv)
let bool_fv = pack_fv bool_lid
let bool_ty = pack_ln (Tv_FVar bool_fv)
let u_zero = pack_universe Uv_Zero
let u_max u1 u2 = pack_universe (Uv_Max [u1; u2])
let u_succ u = pack_universe (Uv_Succ u)
let tm_type u = pack_ln (Tv_Type u)
let tm_prop =
let prop_fv = R.pack_fv R.prop_qn in
R.pack_ln (Tv_FVar prop_fv)
let eqtype_lid : R.name = ["Prims"; "eqtype"]
let true_bool = pack_ln (Tv_Const C_True)
let false_bool = pack_ln (Tv_Const C_False)
let eq2 (u:universe) (t v0 v1:term)
: term
= let eq2 = pack_fv eq2_qn in
let eq2 = pack_ln (Tv_UInst eq2 [u]) in
let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in
let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in
let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in
h2
let b2t_lid : R.name = ["Prims"; "b2t"]
let b2t_fv : R.fv = R.pack_fv b2t_lid
let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero)))
////////////////////////////////////////////////////////////////////////////////
// freevars
////////////////////////////////////////////////////////////////////////////////
let rec freevars (e:term)
: FStar.Set.set var
= match inspect_ln e with
| Tv_Uvar _ _ -> Set.complement Set.empty
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_BVar _ -> Set.empty
| Tv_Var x -> Set.singleton (namedv_uniq x)
| Tv_App e1 (e2, _) ->
Set.union (freevars e1) (freevars e2)
| Tv_Abs b body ->
Set.union (freevars_binder b) (freevars body)
| Tv_Arrow b c ->
Set.union (freevars_binder b) (freevars_comp c)
| Tv_Refine b f ->
freevars (binder_sort b) `Set.union`
freevars f
| Tv_Let recf attrs b def body ->
freevars_terms attrs `Set.union`
freevars (binder_sort b) `Set.union`
freevars def `Set.union`
freevars body
| Tv_Match scr ret brs ->
freevars scr `Set.union`
freevars_opt ret freevars_match_returns `Set.union`
freevars_branches brs
| Tv_AscribedT e t tac b ->
freevars e `Set.union`
freevars t `Set.union`
freevars_opt tac freevars
| Tv_AscribedC e c tac b ->
freevars e `Set.union`
freevars_comp c `Set.union`
freevars_opt tac freevars
and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var))
: FStar.Set.set var
= match o with
| None -> Set.empty
| Some x -> f x
and freevars_comp (c:comp)
: FStar.Set.set var
= match inspect_comp c with
| C_Total t
| C_GTotal t ->
freevars t
| C_Lemma pre post pats ->
freevars pre `Set.union`
freevars post `Set.union`
freevars pats
| C_Eff us eff_name res args decrs ->
freevars res `Set.union`
freevars_args args `Set.union`
freevars_terms decrs
and freevars_args (ts:list argv)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| (t,q)::ts ->
freevars t `Set.union`
freevars_args ts
and freevars_terms (ts:list term)
: FStar.Set.set var
= match ts with
| [] -> Set.empty
| t::ts ->
freevars t `Set.union`
freevars_terms ts
and freevars_binder (b:binder)
: Tot (Set.set var) (decreases b)
= let bndr = inspect_binder b in
freevars bndr.sort `Set.union`
freevars_terms bndr.attrs
and freevars_pattern (p:pattern)
: Tot (Set.set var) (decreases p)
= match p with
| Pat_Constant _ ->
Set.empty
| Pat_Cons head univs subpats ->
freevars_patterns subpats
| Pat_Var bv s -> Set.empty
| Pat_Dot_Term topt ->
freevars_opt topt freevars
and freevars_patterns (ps:list (pattern & bool))
: Tot (Set.set var) (decreases ps)
= match ps with
| [] -> Set.empty
| (p, b)::ps ->
freevars_pattern p `Set.union`
freevars_patterns ps
and freevars_branch (br:branch)
: Tot (Set.set var) (decreases br)
= let p, t = br in
freevars_pattern p `Set.union`
freevars t
and freevars_branches (brs:list branch)
: Tot (Set.set var) (decreases brs)
= match brs with
| [] -> Set.empty
| hd::tl -> freevars_branch hd `Set.union` freevars_branches tl
and freevars_match_returns (m:match_returns_ascription)
: Tot (Set.set var) (decreases m)
= let b, (ret, as_, eq) = m in
let b = freevars_binder b in
let ret =
match ret with
| Inl t -> freevars t
| Inr c -> freevars_comp c
in
let as_ = freevars_opt as_ freevars in
b `Set.union` ret `Set.union` as_
let rec ln' (e:term) (n:int)
: Tot bool (decreases e)
= match inspect_ln e with
| Tv_UInst _ _
| Tv_FVar _
| Tv_Type _
| Tv_Const _
| Tv_Unknown
| Tv_Unsupp
| Tv_Var _ -> true
| Tv_BVar m -> bv_index m <= n
| Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n
| Tv_Abs b body ->
ln'_binder b n &&
ln' body (n + 1)
| Tv_Arrow b c ->
ln'_binder b n &&
ln'_comp c (n + 1)
| Tv_Refine b f ->
ln'_binder b n &&
ln' f (n + 1)
| Tv_Uvar _ _ ->
false
| Tv_Let recf attrs b def body ->
ln'_terms attrs n &&
ln'_binder b n &&
(if recf then ln' def (n + 1) else ln' def n) &&
ln' body (n + 1)
| Tv_Match scr ret brs ->
ln' scr n &&
(match ret with
| None -> true
| Some m -> ln'_match_returns m n) &&
ln'_branches brs n
| Tv_AscribedT e t tac b ->
ln' e n &&
ln' t n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
| Tv_AscribedC e c tac b ->
ln' e n &&
ln'_comp c n &&
(match tac with
| None -> true
| Some tac -> ln' tac n)
and ln'_comp (c:comp) (i:int)
: Tot bool (decreases c)
= match inspect_comp c with
| C_Total t
| C_GTotal t -> ln' t i
| C_Lemma pre post pats ->
ln' pre i &&
ln' post i &&
ln' pats i
| C_Eff us eff_name res args decrs ->
ln' res i &&
ln'_args args i &&
ln'_terms decrs i
and ln'_args (ts:list argv) (i:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| (t,q)::ts ->
ln' t i &&
ln'_args ts i
and ln'_binder (b:binder) (n:int)
: Tot bool (decreases b)
= let bndr = inspect_binder b in
ln' bndr.sort n &&
ln'_terms bndr.attrs n
and ln'_terms (ts:list term) (n:int)
: Tot bool (decreases ts)
= match ts with
| [] -> true
| t::ts -> ln' t n && ln'_terms ts n
and ln'_patterns (ps:list (pattern & bool)) (i:int)
: Tot bool
(decreases ps)
= match ps with
| [] -> true
| (p, b)::ps ->
let b0 = ln'_pattern p i in
let n = binder_offset_pattern p in
let b1 = ln'_patterns ps (i + n) in
b0 && b1
and ln'_pattern (p:pattern) (i:int)
: Tot bool
(decreases p)
= match p with
| Pat_Constant _ -> true
| Pat_Cons head univs subpats ->
ln'_patterns subpats i
| Pat_Var bv s -> true
| Pat_Dot_Term topt ->
(match topt with
| None -> true
| Some t -> ln' t i)
and ln'_branch (br:branch) (i:int)
: Tot bool (decreases br)
= let p, t = br in
let b = ln'_pattern p i in
let j = binder_offset_pattern p in
let b' = ln' t (i + j) in
b&&b'
and ln'_branches (brs:list branch) (i:int)
: Tot bool (decreases brs)
= match brs with
| [] -> true
| br::brs ->
ln'_branch br i &&
ln'_branches brs i
and ln'_match_returns (m:match_returns_ascription) (i:int)
: Tot bool (decreases m)
= let b, (ret, as_, eq) = m in
let b = ln'_binder b i in
let ret =
match ret with
| Inl t -> ln' t (i + 1)
| Inr c -> ln'_comp c (i + 1)
in
let as_ =
match as_ with
| None -> true
| Some t -> ln' t (i + 1)
in
b && ret && as_
let ln (t:term) = ln' t (-1)
let ln_comp (c:comp) = ln'_comp c (-1)
//
// term_ctxt is used to define the equiv relation later,
// basically putting two equiv terms in a hole gives equiv terms
//
// The abs, arrow, refine, and let cases don't seem right here,
// since to prove their equiv, we need to extend gamma for their bodies
//
// If this is useful only for app, then may be we should remove it,
// and add app rules to the equiv relation itself
[@@ no_auto_projectors]
noeq
type term_ctxt =
| Ctxt_hole : term_ctxt
| Ctxt_app_head : term_ctxt -> argv -> term_ctxt
| Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt
// | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt
// | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt
// | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt
// | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt
// | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt
// | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt
// | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt
// | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt
// | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt
// | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt
// and bv_ctxt =
// | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt
// and binder_ctxt =
// | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt
// and comp_ctxt =
// | Ctxt_total : term_ctxt -> comp_ctxt
// | Ctxt_gtotal : term_ctxt -> comp_ctxt
let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) =
match e with
| Ctxt_hole -> t
| Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg)
| Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q))
// | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body)
// | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t))
// | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c)
// | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t))
// | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi)
// | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t))
// | Ctxt_let_sort b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body)
// | Ctxt_let_def b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body)
// | Ctxt_let_body b attrs bv sort def body ->
// pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t))
// | Ctxt_match_scrutinee sc ret brs ->
// pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs)
// and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) =
// let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in
// pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t}
// and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) =
// match c with
// | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t))
// | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t))
noeq
type constant_typing: vconst -> term -> Type0 =
| CT_Unit: constant_typing C_Unit unit_ty
| CT_True: constant_typing C_True bool_ty
| CT_False: constant_typing C_False bool_ty
[@@ no_auto_projectors]
noeq
type univ_eq : universe -> universe -> Type0 =
| UN_Refl :
u:universe ->
univ_eq u u
| UN_MaxCongL :
u:universe ->
u':universe ->
v:universe ->
univ_eq u u' ->
univ_eq (u_max u v) (u_max u' v)
| UN_MaxCongR :
u:universe ->
v:universe ->
v':universe ->
univ_eq v v' ->
univ_eq (u_max u v) (u_max u v')
| UN_MaxComm:
u:universe ->
v:universe ->
univ_eq (u_max u v) (u_max v u)
| UN_MaxLeq:
u:universe ->
v:universe ->
univ_leq u v ->
univ_eq (u_max u v) v
and univ_leq : universe -> universe -> Type0 =
| UNLEQ_Refl:
u:universe ->
univ_leq u u
| UNLEQ_Succ:
u:universe ->
v:universe ->
univ_leq u v ->
univ_leq u (u_succ v)
| UNLEQ_Max:
u:universe ->
v:universe ->
univ_leq u (u_max u v)
let mk_if (scrutinee then_ else_:R.term) : R.term =
pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_);
(Pat_Constant C_False, else_)])
// effect and type
type comp_typ = T.tot_or_ghost & typ
let close_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) [ ND x i ]
let close_comp_typ (c:comp_typ) (x:var) =
close_comp_typ' c x 0
let open_comp_typ' (c:comp_typ) (x:var) (i:nat) =
fst c, subst_term (snd c) (open_with_var x i)
let open_comp_typ (c:comp_typ) (x:var) =
open_comp_typ' c x 0
let freevars_comp_typ (c:comp_typ) = freevars (snd c)
let mk_comp (c:comp_typ) : R.comp =
match fst c with
| T.E_Total -> mk_total (snd c)
| T.E_Ghost -> mk_ghost (snd c)
let mk_arrow_ct ty qual (c:comp_typ) : R.term =
R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c))
type relation =
| R_Eq
| R_Sub
let binding = var & term
let bindings = list binding
let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs
let rec extend_env_l (g:env) (bs:bindings)
: env
= match bs with
| [] -> g
| (x,t)::bs -> extend_env (extend_env_l g bs) x t
//
// TODO: support for erasable attribute
//
let is_non_informative_name (l:name) : bool =
l = R.unit_lid ||
l = R.squash_qn ||
l = ["FStar"; "Ghost"; "erased"]
let is_non_informative_fv (f:fv) : bool =
is_non_informative_name (inspect_fv f)
let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
subst_term (__close_term_vs (i+1) vs t) [ND v i]
let close_term_vs (vs : list var) (t : term) : term =
__close_term_vs 0 vs t
let close_term_bs (bs : list binding) (t : term) : term =
close_term_vs (List.Tot.map fst bs) t
let bindings_to_refl_bindings (bs : list binding) : list R.binding =
L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
let refl_bindings_to_bindings (bs : list R.binding) : list binding =
L.map (fun b -> b.uniq, b.sort) bs
[@@ no_auto_projectors]
noeq
type non_informative : env -> term -> Type0 =
| Non_informative_type:
g:env ->
u:universe ->
non_informative g (pack_ln (Tv_Type u))
| Non_informative_fv:
g:env ->
x:fv{is_non_informative_fv x} ->
non_informative g (pack_ln (Tv_FVar x))
| Non_informative_uinst:
g:env ->
x:fv{is_non_informative_fv x} ->
us:list universe ->
non_informative g (pack_ln (Tv_UInst x us))
| Non_informative_app:
g:env ->
t:term ->
arg:argv ->
non_informative g t ->
non_informative g (pack_ln (Tv_App t arg))
| Non_informative_total_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g t1 ->
non_informative g (mk_arrow_ct t0 q (T.E_Total, t1))
| Non_informative_ghost_arrow:
g:env ->
t0:term ->
q:aqualv ->
t1:term ->
non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1))
| Non_informative_token:
g:env ->
t:typ ->
squash (T.non_informative_token g t) ->
non_informative g t
val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0
val bindings_ok_pat_constant :
g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c))
let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 =
bindings_ok_for_pat g bs (fst br)
let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) =
zip2prop (bindings_ok_for_branch g) bss brs
let binding_to_namedv (b:R.binding) : Tot namedv =
pack_namedv {
RD.uniq = b.uniq;
RD.sort = seal b.sort;
RD.ppname = b.ppname;
}
(* Elaborates the p pattern into a term, using the bs bindings for the
pattern variables. The resulting term is properly scoped only on an
environment which contains all of bs. See for instance the branch_typing
judg. Returns an option, since this can fail if e.g. there are not
enough bindings, and returns the list of unused binders as well, which
should be empty if the list of binding was indeed ok. *)
let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) =
match p, bs with
| Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs)
| Pat_Cons fv univs subpats, bs ->
let head = pack_ln (Tv_FVar fv) in
fold_left_dec
(Some (head, bs))
subpats
(fun st pi ->
let (p,i) = pi in
match st with | None -> None | Some (head, bs) ->
match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs'))
| Pat_Var _ _, b::bs ->
Some (pack_ln (Tv_Var (binding_to_namedv b)), bs)
| Pat_Dot_Term (Some t), _ -> Some (t, bs)
| Pat_Dot_Term None, _ -> None
| _ -> None
[@@ no_auto_projectors]
noeq
type typing : env -> term -> comp_typ -> Type0 =
| T_Token :
g:env ->
e:term ->
c:comp_typ ->
squash (T.typing_token g e c) ->
typing g e c
| T_Var :
g:env ->
x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } ->
typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x)))
| T_FVar :
g:env ->
x:fv { Some? (lookup_fvar g x) } ->
typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x))
| T_UInst :
g:env ->
x:fv ->
us:list universe { Some? (lookup_fvar_uinst g x us) } ->
typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us))
| T_Const:
g:env ->
v:vconst ->
t:term ->
constant_typing v t ->
typing g (constant_as_term v) (T.E_Total, t)
| T_Abs :
g:env ->
x:var { None? (lookup_bvar g x) } ->
ty:term ->
body:term { ~(x `Set.mem` freevars body) } ->
body_c:comp_typ ->
u:universe ->
pp_name:pp_name_t ->
q:aqualv ->
ty_eff:T.tot_or_ghost ->
typing g ty (ty_eff, tm_type u) ->
typing (extend_env g x ty) (open_term body x) body_c ->
typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body))
(T.E_Total,
pack_ln (Tv_Arrow (mk_binder pp_name ty q)
(mk_comp (close_comp_typ body_c x))))
| T_App :
g:env ->
e1:term ->
e2:term ->
x:binder ->
t:term ->
eff:T.tot_or_ghost ->
typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) ->
typing g e2 (eff, binder_sort x) ->
typing g (pack_ln (Tv_App e1 (e2, binder_qual x)))
(eff, open_with t e2)
| T_Let:
g:env ->
x:var { None? (lookup_bvar g x) } ->
e1:term ->
t1:typ ->
e2:term ->
t2:typ ->
eff:T.tot_or_ghost ->
pp_name:pp_name_t ->
typing g e1 (eff, t1) ->
typing (extend_env g x t1) (open_term e2 x) (eff, t2) ->
typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1)
| T_Arrow:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t1:term ->
t2:term { ~(x `Set.mem` freevars t2) } ->
u1:universe ->
u2:universe ->
pp_name:pp_name_t ->
q:aqualv ->
eff:T.tot_or_ghost ->
t1_eff:T.tot_or_ghost ->
t2_eff:T.tot_or_ghost ->
typing g t1 (t1_eff, tm_type u1) ->
typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) ->
typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2))))
(T.E_Total, tm_type (u_max u1 u2))
| T_Refine:
g:env ->
x:var { None? (lookup_bvar g x) } ->
t:term ->
e:term { ~(x `Set.mem` freevars e) } ->
u1:universe ->
u2:universe ->
t_eff:T.tot_or_ghost ->
e_eff:T.tot_or_ghost ->
typing g t (t_eff, tm_type u1) ->
typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) ->
typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1)
| T_PropIrrelevance:
g:env ->
e:term ->
t:term ->
e_eff:T.tot_or_ghost ->
t_eff:T.tot_or_ghost ->
typing g e (e_eff, t) ->
typing g t (t_eff, tm_prop) ->
typing g (`()) (T.E_Total, t)
| T_Sub:
g:env ->
e:term ->
c:comp_typ ->
c':comp_typ ->
typing g e c ->
sub_comp g c c' ->
typing g e c'
| T_If:
g:env ->
scrutinee:term ->
then_:term ->
else_:term ->
ty:term ->
u_ty:universe ->
hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } ->
eff:T.tot_or_ghost ->
ty_eff:T.tot_or_ghost ->
typing g scrutinee (eff, bool_ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) ->
typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) ->
typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp
typing g (mk_if scrutinee then_ else_) (eff, ty)
| T_Match:
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc : term ->
ty_eff:T.tot_or_ghost ->
typing g sc_ty (ty_eff, tm_type sc_u) ->
eff:T.tot_or_ghost ->
typing g sc (eff, sc_ty) ->
branches:list branch ->
ty:comp_typ ->
bnds:list (list R.binding) ->
complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns
branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type
typing g (pack_ln (Tv_Match sc None branches)) ty
and related : env -> term -> relation -> term -> Type0 =
| Rel_refl:
g:env ->
t:term ->
rel:relation ->
related g t rel t
| Rel_sym:
g:env ->
t0:term ->
t1:term ->
related g t0 R_Eq t1 ->
related g t1 R_Eq t0
| Rel_trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
rel:relation ->
related g t0 rel t1 ->
related g t1 rel t2 ->
related g t0 rel t2
| Rel_univ:
g:env ->
u:universe ->
v:universe ->
univ_eq u v ->
related g (tm_type u) R_Eq (tm_type v)
| Rel_beta:
g:env ->
t:typ ->
q:aqualv ->
e:term { ln' e 0 } ->
arg:term { ln arg } ->
related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q)))
R_Eq
(subst_term e [ DT 0 arg ])
| Rel_eq_token:
g:env ->
t0:term ->
t1:term ->
squash (T.equiv_token g t0 t1) ->
related g t0 R_Eq t1
| Rel_subtyping_token:
g:env ->
t0:term ->
t1:term ->
squash (T.subtyping_token g t0 t1) ->
related g t0 R_Sub t1
| Rel_equiv:
g:env ->
t0:term ->
t1:term ->
rel:relation ->
related g t0 R_Eq t1 ->
related g t0 rel t1
| Rel_arrow:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
c1:comp_typ ->
c2:comp_typ ->
rel:relation ->
x:var{
None? (lookup_bvar g x) /\
~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2))
} ->
related g t2 rel t1 ->
related_comp (extend_env g x t2)
(open_comp_typ c1 x)
rel
(open_comp_typ c2 x) ->
related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2)
| Rel_abs:
g:env ->
t1:term ->
t2:term ->
q:aqualv ->
e1:term ->
e2:term ->
x:var{
None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2))
} ->
related g t1 R_Eq t2 ->
related (extend_env g x t1)
(subst_term e1 (open_with_var x 0))
R_Eq
(subst_term e2 (open_with_var x 0)) ->
related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2)
| Rel_ctxt:
g:env ->
t0:term ->
t1:term ->
ctxt:term_ctxt ->
related g t0 R_Eq t1 ->
related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1)
and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 =
| Relc_typ:
g:env ->
t0:term ->
t1:term ->
eff:T.tot_or_ghost ->
rel:relation ->
related g t0 rel t1 ->
related_comp g (eff, t0) rel (eff, t1)
| Relc_total_ghost:
g:env ->
t:term ->
related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t)
| Relc_ghost_total:
g:env ->
t:term ->
non_informative g t ->
related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t)
and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (brs:list branch) -> (bnds : list (list R.binding)) -> Type0
=
(* This judgement only enforces that branch_typing holds for every
element of brs and its respective bnds (which must have the same
length). *)
| BT_Nil :
branches_typing g sc_u sc_ty sc rty [] []
| BT_S :
br : branch ->
bnds : list R.binding ->
pf : branch_typing g sc_u sc_ty sc rty br bnds ->
rest_br : list branch ->
rest_bnds : list (list R.binding) ->
rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds ->
branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds)
and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ)
: (br : branch) -> (bnds : list R.binding) -> Type0
=
| BO :
pat : pattern ->
bnds : list R.binding{bindings_ok_for_pat g bnds pat} ->
hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} ->
body:term ->
_ : squash (Some? (elaborate_pat pat bnds)) ->
typing (extend_env
(extend_env_l g (refl_bindings_to_bindings bnds))
hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds))))
)
body rty ->
branch_typing g sc_u sc_ty sc rty
(pat, close_term_bs (refl_bindings_to_bindings bnds) body)
bnds
and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 =
| MC_Tok :
env:_ ->
sc:_ ->
ty:_ ->
pats:_ ->
bnds:_ ->
squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds
and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2
and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2
and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2
type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t)
type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t)
val subtyping_token_renaming (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0))
(rename t0 x y)
(rename t1 x y)
val subtyping_token_weakening (g:env)
(bs0:bindings)
(bs1:bindings)
(x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) })
(t:term)
(t0 t1:term)
(d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1)
: T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1
let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe)
(d:typing g t (T.E_Total, tm_type (u_max u u)))
: typing g t (T.E_Total, tm_type u)
= let ue
: univ_eq (u_max u u) u
= UN_MaxLeq u u (UNLEQ_Refl u)
in
let du : related g (tm_type (u_max u u)) R_Eq (tm_type u)
= Rel_univ g (u_max u u) u ue in
let du : related g (tm_type (u_max u u)) R_Sub (tm_type u)
= Rel_equiv _ _ _ _ du in
T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du)
val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: Lemma (ensures ln e /\ ln (snd c))
val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c)
: GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u))
val binder_offset_pattern_invariant (p:pattern) (ss:subst)
: Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss))
val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst)
: Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss))
val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var)
: Lemma
(ensures subst_term
(subst_term t [ ND x i ])
(open_with_var x i)
== t)
val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var)
: Lemma (ensures subst_binder
(subst_binder b [ ND x i ])
(open_with_var x i)
== b)
val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var)
: Lemma (ensures subst_terms
(subst_terms ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var)
: Lemma
(ensures subst_comp
(subst_comp c [ ND x i ])
(open_with_var x i)
== c)
val open_close_inverse'_args (i:nat)
(ts:list argv { ln'_args ts (i - 1) })
(x:var)
: Lemma
(ensures subst_args
(subst_args ts [ ND x i ])
(open_with_var x i)
== ts)
val open_close_inverse'_patterns (i:nat)
(ps:list (pattern & bool) { ln'_patterns ps (i - 1) })
(x:var)
: Lemma
(ensures subst_patterns
(subst_patterns ps [ ND x i ])
(open_with_var x i)
== ps)
val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var)
: Lemma
(ensures subst_pattern
(subst_pattern p [ ND x i ])
(open_with_var x i)
== p)
val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var)
: Lemma
(ensures subst_branch
(subst_branch br [ ND x i ])
(open_with_var x i)
== br)
val open_close_inverse'_branches (i:nat)
(brs:list branch { ln'_branches brs (i - 1) })
(x:var)
: Lemma
(ensures subst_branches
(subst_branches brs [ ND x i ])
(open_with_var x i)
== brs)
val open_close_inverse'_match_returns (i:nat)
(m:match_returns_ascription { ln'_match_returns m (i - 1) })
(x:var)
: Lemma
(ensures subst_match_returns
(subst_match_returns m [ ND x i ])
(open_with_var x i)
== m)
val open_close_inverse (e:R.term { ln e }) (x:var)
: Lemma (open_term (close_term e x) x == e)
val close_open_inverse' (i:nat)
(t:term)
(x:var { ~(x `Set.mem` freevars t) })
: Lemma
(ensures subst_term
(subst_term t (open_with_var x i))
[ ND x i ]
== t)
val close_open_inverse'_comp (i:nat)
(c:comp)
(x:var{ ~(x `Set.mem` freevars_comp c) })
: Lemma
(ensures subst_comp
(subst_comp c (open_with_var x i))
[ ND x i ]
== c)
val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) })
: Lemma
(ensures subst_args
(subst_args args (open_with_var x i))
[ ND x i]
== args)
val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) })
: Lemma
(ensures subst_binder
(subst_binder b (open_with_var x i))
[ ND x i ]
== b)
val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) })
: Lemma
(ensures subst_terms
(subst_terms ts (open_with_var x i))
[ ND x i ]
== ts)
val close_open_inverse'_branches (i:nat) (brs:list branch)
(x:var{ ~(x `Set.mem` freevars_branches brs) })
: Lemma
(ensures subst_branches
(subst_branches brs (open_with_var x i))
[ ND x i ]
== brs)
val close_open_inverse'_branch (i:nat)
(br:branch)
(x:var{ ~(x `Set.mem` freevars_branch br) })
: Lemma
(ensures subst_branch
(subst_branch br (open_with_var x i))
[ ND x i ]
== br)
val close_open_inverse'_pattern (i:nat)
(p:pattern)
(x:var{ ~(x `Set.mem` freevars_pattern p) })
: Lemma
(ensures subst_pattern
(subst_pattern p (open_with_var x i))
[ ND x i ]
== p)
val close_open_inverse'_patterns (i:nat)
(ps:list (pattern & bool))
(x:var {~ (x `Set.mem` freevars_patterns ps) })
: Lemma
(ensures subst_patterns
(subst_patterns ps (open_with_var x i))
[ ND x i ]
== ps)
val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription)
(x:var{ ~(x `Set.mem` freevars_match_returns m) })
: Lemma
(ensures subst_match_returns
(subst_match_returns m (open_with_var x i))
[ ND x i ]
== m)
val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) })
: Lemma (close_term (open_term e x) x == e)
//
// fst has corresponding lemmas for other syntax classes
//
val close_with_not_free_var (t:R.term) (x:var) (i:nat)
: Lemma
(requires ~ (Set.mem x (freevars t)))
(ensures subst_term t [ ND x i ] == t)
// this also requires x to be not in freevars e1 `Set.union` freevars e2
val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var { None? (lookup_bvar g x) })
(eq:equiv (extend_env g x ty)
(subst_term e1 (open_with_var x 0))
(subst_term e2 (open_with_var x 0)))
: equiv g (mk_arrow ty q e1)
(mk_arrow ty q e2)
// the proof for this requires e1 and e2 to be ln
val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv)
(x:var{None? (lookup_bvar g x)})
(eq:equiv (extend_env g x ty) e1 e2)
: equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ]))
(mk_abs ty q (subst_term e2 [ ND x 0 ]))
val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat)
: Lemma
(requires ln' e i /\ i < j)
(ensures subst_term e [ DT j t ] == e)
[SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])]
//
// Type of the top-level tactic that would splice-in the definitions
//
let fstar_env_fvs (g:R.env) =
lookup_fvar g unit_fv == Some (tm_type u_zero) /\
lookup_fvar g bool_fv == Some (tm_type u_zero) /\
lookup_fvar g b2t_fv == Some b2t_ty
type fstar_env = g:R.env{fstar_env_fvs g}
type fstar_top_env = g:fstar_env {
forall x. None? (lookup_bvar g x )
}
//
// This doesn't allow for universe polymorphic definitions
//
// May be we can change it to:
//
// g:fstar_top_env -> T.tac ((us, e, t):(univ_names & term & typ){typing (push g us) e t})
//
noeq
type sigelt_typing : env -> sigelt -> Type0 =
| ST_Let :
g : env ->
fv : R.fv ->
ty : R.typ ->
tm : R.term ->
squash (typing g tm (T.E_Total, ty)) ->
sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm })]))
| ST_Let_Opaque :
g : env ->
fv : R.fv ->
ty : R.typ ->
(* no tm: only a proof of existence *)
squash (exists (tm:R.term). typing g tm (T.E_Total, ty)) ->
sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) })]))
(**
* The type of the top-level tactic that would splice-in the definitions.
* It returns a list of well typed definitions, via the judgment above.
*
* Each definition can have a 'blob' attached with a given name.
* The blob can be used later, e.g., during extraction, and passed back to the
* extension to perform additional processing.
*)
(*
* It returns either:
* - Some tm, blob, typ, with a proof that `typing g tm typ`
* - None, blob, typ), with a proof that `exists tm. typing g tm typ`
* The blob itself is optional and can store some additional metadata that
* constructed by the tactic. If present, it will be stored in the
* sigmeta_extension_data field of the enclosing sigelt.
*
*)
let blob = string & R.term
(* If checked is true, this sigelt is properly typed for the environment. If not,
we don't know and let F* re-typecheck the sigelt. *)
let sigelt_for (g:env) =
tup:(bool & sigelt & option blob)
{
let (checked, se, _) = tup in
checked ==> sigelt_typing g se
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Reflection.V2.Data.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.Inhabited.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.Typing.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Reflection.V2.Data",
"short_module": "RD"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: FStar.Stubs.Reflection.Types.env -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"Prims.list",
"FStar.Reflection.Typing.sigelt_for"
] | [] | false | false | false | true | true | let dsl_tac_result_t (g: env) =
| list (sigelt_for g) | false |