text stringlengths 12 786k |
|---|
type location = | Parameter of int list | Field of string | Nowhere |
module StringMap = Map . Make ( String ) String |
type t = location StringMap . t |
let make l = List . fold_left ( fun acc ( id , _ ) _ -> if StringMap . mem id acc then acc else StringMap . add id ( Field ( " w " ^ id ) id ) id acc ) acc StringMap . empty l |
let size t = StringMap . cardinal t |
let mem k t = StringMap . mem k t |
let find k t = StringMap . find k t |
let add k v t = if not ( StringMap . mem k t ) t then StringMap . add k v t else t |
let iter f t = StringMap . iter f t |
let fold f t z = StringMap . fold f t z |
let add_parameter t s l = t := add s ( Parameter l ) l ! t |
let add_field t s f = t := add s ( Field f ) f ! t |
let add_nowhere t s = t := add s Nowhere ! t |
let rec type_desc ~ mode ( ? bracket = false ) fmt = function | Tvar None -> fprintf fmt " _ " | Tvar ( Some name ) -> fprintf fmt " ' % s " name | Ttuple typs -> fprintf fmt " [ @< 1 >% a ] " @ tuple typs | Tarrow ( typ1 , typ2 , implicitness , label ) -> if bracke... |
let field_decl fmt decl = fprintf fmt " % a :@ [ @< hv >% a ] " @ Ident . pprint decl . fld_ident type_expr decl . fld_type |
let ctor_args fmt = function | Ctor_tuple [ ] -> ( ) | Ctor_tuple typs -> tuple fmt typs | Ctor_record { tdec_desc = TRecord fields ; _ } -> fprintf fmt " { [ @< 2 >% a ] } " @ ( pp_print_list ~ pp_sep : comma_sep field_decl ) fields | Ctor_record _ -> assert false |
let ctor_decl fmt decl = fprintf fmt " % a % a " Ident . pprint decl . ctor_ident ctor_args decl . ctor_args ; match decl . ctor_ret with | Some typ -> fprintf fmt " @ :@ [ @< hv >% a ] " @ type_expr typ | None -> ( ) |
let type_decl_desc fmt = function | TAbstract -> ( ) | TAlias typ -> fprintf fmt " @ =@ [ @< hv >% a ] " @ type_expr typ | TRecord fields -> fprintf fmt " @ =@ { [ @< hv2 >% a ] } " @ ( pp_print_list ~ pp_sep : comma_sep field_decl ) fields | TVariant ctors -> fprintf fm... |
let type_decl ident fmt decl = fprintf fmt " type % a " Ident . pprint ident ; ( match decl . tdec_params with [ ] -> ( ) | _ -> tuple fmt decl . tdec_params ) ; type_decl_desc fmt decl . tdec_desc |
let rec basic_check l current_type expected_type loc = if expected_type <> current_type && not ( is_unknown current_type ) then ( assert ( not debug ) ; raise ( TypeError ( expected_type , current_type , loc ) ) ) ; List . iter ( fun e -> typer e expected_type ) l if body . t <>... |
let test_assert_is_none context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import unittest class FakeTest ( unittest . TestCase ) : def foo ( self ) -> None : self . assertIsNotNone ( 2 ) } | [ ] ; assert_type_errors { | import typing import u... |
let test_assert_is context = assert_type_errors ~ context { | from typing import Type class Foo : x : int = 1 def foo ( o : Type [ object ] ) -> None : if ( o is Foo ) : o . x } | [ ] ; ( ) |
let test_check_global_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing class A : def __init__ ( self , x : typing . Optional [ int ] ) -> None : self . x = x def call ( ) -> None : pass def foo ( ) -> None : a = A (... |
let test_check_local_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . Optional [ int ] ) -> None : if x : reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` ty... |
let test_check_if_else_clause context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . Optional [ int ] ) -> None : if x is None : reveal_type ( x ) else : reveal_type ( x ) } | [ " Revealed type [ - 1 ] : R... |
let test_assert_contains_none context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . List [ typing . Optional [ int ] ] ) -> None : assert None not ... |
let test_check_callable context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Dict , Optional class CallableClass : def __call__ ( self , x : int ) -> str : return " A " def foo ( x : Dict [ int , Optional [ CallableClass ] ] ) ... |
let test_check_final_attribute_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Final , Optional class Boo : . . . class Baz : z : Final [ Optional [ Boo ] ] = None class Bar : y : Final [ Optional [ Baz ] ] = No... |
let test_check_temporary_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | MY_GLOBAL = 1 . 0 def arbitrary_call ( ) -> None : pass def test ( ) -> None : reveal_type ( MY_GLOBAL ) global MY_GLOBAL MY_GLOBAL = 1 reveal_type ( MY_GLOBAL ) ... |
let ( ) = " refinement " >::: [ " check_assert_is_none " >:: test_assert_is_none ; " check_assert_is " >:: test_assert_is ; " check_global_refinement " >:: test_check_global_refinement ; " check_local_refinement " >:: test_check_local_refinement ; " check_if_else_clause " >:... |
module type S = sig type t val typerep_of_t : t Typerep . t val typename_of_t : t Typename . t end |
module type S1 = sig type ' a t val typerep_of_t : ' a Typerep . t -> ' a t Typerep . t val typename_of_t : ' a Typename . t -> ' a t Typename . t end |
module type S2 = sig type ( ' a , ' b ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ( ' a , ' b ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ( ' a , ' b ) t Typename . t end |
module type S3 = sig type ( ' a , ' b , ' c ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ( ' a , ' b , ' c ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ' c Typename . t -> ( ' a , ' b... |
module type S4 = sig type ( ' a , ' b , ' c , ' d ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ' d Typerep . t -> ( ' a , ' b , ' c , ' d ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ... |
module type S5 = sig type ( ' a , ' b , ' c , ' d , ' e ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ' d Typerep . t -> ' e Typerep . t -> ( ' a , ' b , ' c , ' d , ' e ) t Typerep . t val typename_of_t : ' a ... |
let repr_of_poly_variant : [ > ] -> int = fun variant -> let obj = Obj . repr variant in if Obj . is_int obj then Obj . obj obj else ( let size = Obj . size obj in assert ( size = 2 ) ; let repr = Obj . field obj 0 in assert ( Obj . is_int repr ) ; Obj . obj repr ) ; ; |
let hash_variant s = let accu = ref 0 in for i = 0 to String . length s - 1 do accu := ( 223 * ! accu ) + Char . code s . [ i ] done ; accu := ! accu land ( ( 1 lsl 31 ) - 1 ) ; if ! accu > 0x3FFFFFFF then ! accu - ( 1 lsl 31 ) else ! accu ; ; |
let ( ) = assert ( repr_of_poly_variant ` Latency_stats = hash_variant " Latency_stats " ) |
let ( ) = assert ( repr_of_poly_variant ` zero = hash_variant " zero " ) |
let double_array_value = Obj . magic 0 . |
let has_double_array_tag a = Obj . double_array_tag = Obj . tag ( Obj . repr a ) |
let ( ) = let module M = struct type double = { a : float ; b : float } type simple = { c : float ; d : int } let double = { a = double_array_value ; b = double_array_value } let simple = { c = double_array_value ; d = double_array_value } end in assert ( has_double_array_tag... |
type kind_of_global_ident = Value | Type | Constr | Label |
type kind_of_ident = | Current | Initial | Next | Multi | Derivative |
type error = | Evar_undefined of Zident . t | Emissing of Zident . t | Eglobal_undefined of kind_of_global_ident * Lident . t | Eglobal_already of kind_of_global_ident * string | Ealready of kind_of_ident * Zident . t | Ealready_with_different_kinds of kind_of_ident * kind_of_ident * Zident . t |... |
let error loc kind = raise ( Error ( loc , kind ) ) |
type warning = | Wpartial_matching of Zelus . pattern | Wunreachable_state of Zident . t | Wmatch_unused of Zelus . pattern | Wequation_does_not_define_a_name | Wreset_target_state of bool * bool |
let kind_of_global_ident k = match k with | Value -> " value " | Type -> " type " | Constr -> " constructor " | Label -> " label " |
let kind_of_ident k = match k with | Current -> " value " | Derivative -> " derivative " | Initial -> " initial value " | Multi -> " multi emitted value " | Next -> " next value " |
let kind_message kind = match kind with | Tstatic _ -> " static " | Tcont -> " continuous " | Tany -> " combinatorial " | Tdiscrete ( s ) -> if s then " discrete " else " stateless discrete " | Tproba -> " probabilistic " |
let message loc kind = begin match kind with | Evar_undefined ( name ) -> eprintf " [ @% aTyping error : The value identifier % s is unbound . . ] " @@ output_location loc ( Zident . source name ) | Emissing ( s ) -> eprintf " [ @% aType error : no equation is given for name % ... |
let warning loc w = if not ! Zmisc . no_warning then match w with | Wpartial_matching ( p ) -> Format . eprintf " [ @% aType warning : this pattern - matching is not exhaustive . . ] " @@ Format . eprintf " [ @ Here is an example of a value that is not matched . :@% a . ] " ... |
let fresh_env ( ) = let initially_opened_module = if ! Clflags . nopervasives then None else Some " Stdlib " in Typemod . initial_env ~ loc ( : Location . in_file " command line " ) ~ safe_string ( : not ! Clflags . unsafe_string ) ~ initially_opened_module ~ open_implicit_modules ... |
module Rewrite_loc = struct let queue = ref [ ] let update l = if l <> none then match ! queue with | [ ] -> assert false | l ' :: ls -> queue := Location_aux . union l l ' :: ls let enter ( ) = queue := Location . none :: ! queue let leave l0 = match ! queue with | [ ] -> as... |
let rewrite_loc t = Rewrite_loc . start ( ) ; let t = match t with | ` str str -> ` str ( Rewrite_loc . u_structure str ) | ` fake str -> ` fake ( Rewrite_loc . u_structure str ) | ` sg sg -> ` sg ( Rewrite_loc . u_signature sg ) in Rewrite_loc . exit ( ) ; t |
type value = QuotedList of value list | Symbol of string | Keyword of string | Variable of string | Number of int | Boolean of bool | String of string | Plus | Minus | Divide | Multiply | Modulo | LT | LTE | GT | GTE | EQ | NEQ | AND | OR | LParen | RParen | Quote | EOF |
type sexp = Atom of value | List of sexp list |
let boolean_of_string s = match s with | " # f " -> false | _ -> true |
let rec debug_string_of_value value = match value with | QuotedList values -> " ' ( " ( ^ String . concat " , " ( List . map ( fun value -> string_of_value value ) values ) ) " ) " ^ | Symbol s -> " Symbol ( " ^ s " ) " ^ | Variable s -> " Variable ( " ... |
let rec string_of_sexp sexpr = match sexpr with | Atom x -> " Atom ( " ( ^ string_of_value x ) " ) " ^ | List xs -> " List ( " ( ^ String . concat " " ( List . map string_of_sexp xs ) ) " ) " ^ |
type test = { snippet : string ; loc : Lexing . position ; exn : exn } |
let name_table ( defns : Unresolved . t list ) = List . map defns ~ f ( : fun ( def : _ Named . t ) -> ( def . name , def ) ) |> String . Map . of_list_reducei ~ f ( : fun name v1 v2 -> let open Unresolved in match ( v1 . Named . data , v2 . data ) with | Enum_ano... |
let resolve_all ( defns : Unresolved . t list ) = let names = name_table defns in let defns = String . Map . values names in let rename_change_field = object inherit Unresolved . map as super method ! field x = if x . name = " change " then match x . data with | Single { typ = Ident " ... |
let test_snippets s = let fails , succs = List . partition_map s ~ f ( : fun s -> let lexbuf = Lexing . from_string s in try Right ( Ts_parser . main Ts_lexer . token lexbuf ) with | exn -> Left { snippet = s ; loc = lexbuf . lex_curr_p ; exn } ) in ignore ( resolve_all ( List ... |
let pp_results ppf tests = List . iteri tests ~ f ( : fun i { snippet ; loc ; exn } -> Format . pp_print_string ppf snippet ; Format . fprintf ppf " line : % d char : % d . " @ loc . pos_lnum ( loc . pos_cnum - loc . pos_bol ) ; Format . fprintf ppf " % d . exn : %... |
let of_snippets s = List . concat_map s ~ f ( : fun s -> let lexbuf = Lexing . from_string s in try Ts_parser . main Ts_lexer . token lexbuf with | _exn -> [ ] ) |
module Type_var_names = struct let last_char : char ref = ref ' a ' let table : ( Types . type_expr , char ) Hashtbl . t = Hashtbl . create 1024 let reset ( ) = last_char := ' a ' let find t = match Hashtbl . find_opt table t with | None -> Hashtbl . add table t ! last_char ; l... |
module Fun = struct let rec mk_type_expr : Types . type_expr -> Erlang . Ast . type_expr = fun type_expr -> match type_expr . desc with | Tarrow ( _ , _ , _ , _ ) -> ( match Uncurry . from_type_expr type_expr with | ` Uncurried ( args , return ) -> let args = List . map mk_... |
let rec is_unit ( t : Types . type_expr ) = match t . desc with | Tconstr ( p , _ , _ ) -> Path . same p Predef . path_unit | Tlink t ' -> is_unit ( Btype . repr t ' ) | _ -> false |
let is_opaque_in_signature type_decl signature = match signature with | None -> Type . type_ | Some sign -> List . fold_left ( fun kind sig_item -> match sig_item with | Sig_type ( name , { type_manifest = None ; _ } , _ , _ ) when Ident . name name = Ident . name type_decl . typ... |
let rec mk_type_expr core_type = match core_type . ctyp_desc with | Ttyp_any -> Some Type . any | Ttyp_var var_name -> Some ( Type . var ( Name . var var_name ) ) | Ttyp_arrow ( _ , param , out ) -> let rec args t acc = match t . ctyp_desc with | Ttyp_arrow ( _ , p , t ' ) ... |
let mk_record labels = let mk_field Typedtree . { ld_id ; ld_type ; _ } = let rf_name = Names . atom_of_ident ld_id in let rf_type = match mk_type_expr ld_type with Some t -> t | None -> Type . any in Type . map_field ~ presence : Mandatory ( Type . const ( Const . atom rf_name ) ) ... |
let mk_abstract name params type_decl core_type signature = match mk_type_expr core_type with | Some expr -> let kind = is_opaque_in_signature type_decl signature in Some ( Type . mk ~ name ~ params ~ expr ~ kind ) | None -> None |
let mk_type_params params = params |> List . filter_map ( fun ( core_type , _ ) -> match core_type . ctyp_desc with | Ttyp_var name -> Some ( Name . var name ) | _ -> None ) |
let mk_type type_decl ~ signature = let name = Names . atom_of_ident type_decl . typ_id in let params = mk_type_params type_decl . typ_params in let params = List . map Type . var params in match type_decl . typ_kind with | Ttype_abstract -> ( match type_decl . typ_manifest with | Some abs -> m... |
let mk_types : Typedtree . structure -> Types . signature option -> Erlang . Ast . type_decl list = fun typedtree signature -> typedtree . str_items |> List . concat_map ( fun item -> match item . str_desc with Tstr_type ( _ , tys ) -> tys | _ -> [ ] ) |> List . filter_map ( ... |
type inner_curve_var = Tick . Field . t Snarky_backendless . Cvar . t * Tick . Field . t Snarky_backendless . Cvar . t |
module Basic = struct type ( ' var , ' value , ' n1 , ' n2 ) ' n2 t = { max_proofs_verified : ( module Nat . Add . Intf with type n = ' n1 ) ' n1 ; value_to_field_elements : ' value -> Impls . Step . Field . Constant . t array ; var_to_field_elements : ' var -> Impls . Step . Fiel... |
module Side_loaded = struct module Ephemeral = struct type t = { index : [ ` In_circuit of Side_loaded_verification_key . Checked . t | ` In_prover of Side_loaded_verification_key . t ] } end module Permanent = struct type ( ' var , ' value , ' n1 , ' n2 ) ' n2 t = { max_proofs_ver... |
module Compiled = struct type f = Impls . Wrap . field type ( ' a_var , ' a_value , ' max_proofs_verified , ' branches ) ' branches basic = { typ : ( ' a_var , ' a_value ) ' a_value Impls . Step . Typ . t ; proofs_verifieds : ( int , ' branches ) ' branches Vector . t ; var... |
module For_step = struct type ( ' a_var , ' a_value , ' max_proofs_verified , ' branches ) ' branches t = { branches : ' branches Nat . t ; max_proofs_verified : ( module Nat . Add . Intf with type n = ' max_proofs_verified ) ' max_proofs_verified ; proofs_verifieds : ( Impls . S... |
type t = { compiled : Compiled . packed Type_equal . Id . Uid . Table . t ; side_loaded : Side_loaded . packed Type_equal . Id . Uid . Table . t } |
let univ : t = { compiled = Type_equal . Id . Uid . Table . create ( ) ; side_loaded = Type_equal . Id . Uid . Table . create ( ) } |
let find t k = match Hashtbl . find t k with None -> failwith " key not found " | Some x -> x |
let lookup_compiled : type a b n m . ( a , b , n , m ) m Tag . tag -> ( a , b , n , m ) m Compiled . t = fun t -> let ( T ( other_id , d ) d ) d = find univ . compiled ( Type_equal . Id . uid t ) t in let T = Type_equal . Id . same_witness_exn t other_id in d |
let lookup_side_loaded : type a b n m . ( a , b , n , m ) m Tag . tag -> ( a , b , n , m ) m Side_loaded . t = fun t -> let ( T ( other_id , d ) d ) d = find univ . side_loaded ( Type_equal . Id . uid t ) t in let T = Type_equal . Id . same_witness_exn t other_id in d |
let lookup_basic : type a b n m . ( a , b , n , m ) m Tag . t -> ( a , b , n , m ) m Basic . t = fun t -> match t . kind with | Compiled -> Compiled . to_basic ( lookup_compiled t . id ) id | Side_loaded -> Side_loaded . to_basic ( lookup_side_loaded t . id ) id |
let lookup_step_domains : type a b n m . ( a , b , n , m ) m Tag . t -> ( Domain . t , m ) m Vector . t = fun t -> let f = Vector . map ~ f : Domains . h in match t . kind with | Compiled -> f ( lookup_compiled t . id ) id . step_domains | Side_loaded -> ( let t = lookup_... |
let max_proofs_verified : type n1 . ( _ , _ , n1 , _ ) _ Tag . t -> ( module Nat . Add . Intf with type n = n1 ) n1 = fun tag -> match tag . kind with | Compiled -> ( lookup_compiled tag . id ) id . max_proofs_verified | Side_loaded -> ( lookup_side_loaded tag . id ) id . ... |
let typ : type var value . ( var , value , _ , _ ) _ Tag . t -> ( var , value ) value Impls . Step . Typ . t = fun tag -> match tag . kind with | Compiled -> ( lookup_compiled tag . id ) id . typ | Side_loaded -> ( lookup_side_loaded tag . id ) id . permanent . typ |
let value_to_field_elements : type a . ( _ , a , _ , _ ) _ Tag . t -> a -> Tick . Field . t array = fun t -> match t . kind with | Compiled -> ( lookup_compiled t . id ) id . value_to_field_elements | Side_loaded -> ( lookup_side_loaded t . id ) id . permanent . value_to_fi... |
let lookup_map ( type a b c d ) d ( t : ( a , b , c , d ) d Tag . t ) t ~ self ~ default ( ~ f : [ ` Compiled of ( a , b , c , d ) d Compiled . t | ` Side_loaded of ( a , b , c , d ) d Side_loaded . t ] -> _ ) = match Type_equal . Id . same_witness t . id ... |
let add_side_loaded ~ name permanent = let id = Type_equal . Id . create ~ name sexp_of_opaque in Hashtbl . add_exn univ . side_loaded ~ key ( : Type_equal . Id . uid id ) id ~ data ( : T ( id , { ephemeral = None ; permanent } ) ) ; { Tag . kind = Side_loaded ; id } |
let set_ephemeral { Tag . kind ; id } eph = ( match kind with Side_loaded -> ( ) | _ -> failwith " Expected Side_loaded ) " ; Hashtbl . update univ . side_loaded ( Type_equal . Id . uid id ) id ~ f ( : function | None -> assert false | Some ( T ( id , d ) d ) d -> ... |
let add_exn ( type a b c d ) d ( tag : ( a , b , c , d ) d Tag . t ) t ( data : ( a , b , c , d ) d Compiled . t ) t = Hashtbl . add_exn univ . compiled ~ key ( : Type_equal . Id . uid tag . id ) id ~ data ( : Compiled . T ( tag . id , data ) data ) d... |
let test ( ) = print_endline " Types tests " ; let open EH1 in let open Global in init ( ) ; let bool_t = Type . bool ( ) in let int_t = Type . int ( ) in assert ( not Type . ( equal bool_t int_t ) ) ; let real_t = Type . real ( ) in assert ( not Type . ( equal re... |
type error = | Unbound_type_var of string | Wrong_number_args of Path . t * int * int | Expected_type_var of type_expr | Constraints_not_satisfied of type_expr * type_decl | Opaque_type_in_prover_mode of type_expr | Convertible_arities_differ of string * int * string * int | GADT_in_nonrec_type | Repea... |
let type0 { Typedast . type_type ; _ } = type_type |
let unify = ref ( fun ~ loc : _ _env _typ1 _typ2 -> failwith " Undefined " ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.