text
stringlengths
0
601k
let parse_k s = match String . split ( function ' ' | ' \ t ' -> true | _ -> false ) s with | [ " val " ] -> Some KValue | [ " type " ] -> Some KType | [ " typext " ] -> Some KTypext | [ " exception " ] -> Some KTypext | [ " module " ] -> Some KModule | [ " module " ; " type " ] -> Some KModtype | [ " class " ] -> Some...
type value_kind = SVal_prim | SVal_reg [ @@ deriving conv { ocaml_of } , typerep ]
type rec_status = [ % import : Types . rec_status ]
type out_ident = [ % import : Outcometree . out_ident ]
module Flatten ( A : sig type type_expr [ @@ deriving conv { ocaml_of } ] type path [ @@ deriving conv { ocaml_of } ] type ident [ @@ deriving conv { ocaml_of } ] open A type res = | FModule of fmodule * rec_status | FModtype of fmodule option | FType of type_expr list * ftypekind * private_flag * type_expr option * re...
let ( ) = ignore ( Mtype . strengthen == Mtype . strengthen )
let ocaml_of_type_expr ty = Ocaml . String ( Format . sprintf " % a " Printtyp . type_scheme ty )
module Scrape = struct type k = | KValue | KType | KTypext | KModule | KModtype | KClass | KClasstype [ @@ deriving conv { ocaml_of } ] type res = | SModule of smodule * rec_status | SModtype of smodule option | SType of type_expr list * stypekind * private_flag * type_expr option * rec_status | STypext of Path . t * t...
module Simplify = struct include Sig . Flatten ( struct type type_expr = Types . type_expr let ocaml_of_type_expr = ocaml_of_type_expr type path = Path . t let ocaml_of_path = Path . ocaml_of_t type ident = Ident . t let ocaml_of_ident = Ident . ocaml_of_t end ) open Scrape open Path let ident_create_minus n = let id =...
let odot c n = match c with | None -> Oide_ident n | Some p -> Oide_dot ( p , n )
let oapply c n = match c with | None -> assert false | Some p -> Oide_apply ( p , Oide_ident n )
module Scan_ids = struct open Simplify open Path module Make ( A : sig val tbl : ( Ident . t , out_ident ) Hashtbl . t end ) = struct include A let add id p = match Hashtbl . find_opt tbl id with | None -> Hashtbl . add tbl id p | Some p ' -> !!% " ERROR : double binding of % s ( % a and % a ) . " @ ( Ident . string_of...
module Globalized = struct module F = Simplify module Make ( A : sig val rewrite : Path . t -> out_ident end ) = struct include Xprinttyp . Make ( A ) let conv_ty = tree_of_type_scheme let fconstructor_arguments = function | F . FCRecord id_mf_ty_list -> Otyp_record ( map ( fun ( id , mf , ty ) -> id . Ident . name , m...
module Flatten = struct open Sig let rec fmodule = function | FSignature fsg -> fsignature fsg | FFunctor ( _id , _fmo , fm ) -> fmodule fm | FUNKNOWN_ident _p -> [ ] | FUNKNOWN_alias _p -> [ ] and fsignature kid_res_list = flip concat_map kid_res_list & fun x -> match x with | ( KValue , _ ) , FValue _ -> [ x ] | ( KT...
module Rewrite = struct open Path let notfound = Ident . create " NOTOP " let warned_rewrite_idents = ref [ ] let warned_paths = ref [ ] let warned_rewrite_cmis = ref [ ] let rec rewrite f p = match p with | Pident id when Ident . persistent id -> let p = match find_global_module id with | None -> if add_if_not_mem ( i...
module Print = struct open Format open Outcometree let map_over_path path ty = let rec f t = match t with | Otyp_abstract -> t | Otyp_open -> t | Otyp_alias ( t , s ) -> Otyp_alias ( f t , s ) | Otyp_arrow ( s , t1 , t2 ) -> Otyp_arrow ( s , f t1 , f t2 ) | Otyp_class ( b , i , ts ) -> Otyp_class ( b , path i , map f t...
let globalize tbl fsig = let rewrite = memoize & Rewrite . rewrite ( Scan_ids . rewrite tbl ) in let module G = Globalized . Make ( struct let rewrite = rewrite end ) in G . fsignature fsig
let scrape top sg = Reset . typing ( ) ; let env = Env . initial_unsafe_string in let res , res_time = time ( Scrape . signature env ) sg in if res_time > 1 . 0 then !!% " Scrape took . % 02f secs . " @ res_time ; let fsig , sim_time = time Simplify . ssignature res in if sim_time > 1 . 0 then !!% " Simplify took . % 0...
let test top sg = Reset . typing ( ) ; let env = Env . initial_unsafe_string in !!% " scraping . . . . " ; @ let res = Scrape . signature env sg in !!% " % a . " @ Scrape . format res ; let fsig = Simplify . ssignature res in !!% " % a . . " @@ Simplify . format fsig ; let tbl = Scan_ids . scan top fsig in let fsig = g...
module PathLimit = struct type desc = | Apply of desc | Dot of desc * string | Ident of string | IdentMod of string | ModIdent of string | No let decr ( ? by = 1 ) score = let score = score - by in if score < 0 then None else Some score let max t1 t2 = match t1 , t2 with | None , None -> None | None , _ -> t2 | _ , Non...
module TypeLimit = struct type t = { score : int ; expansions : int ; } let create score = { score ; expansions = 50 } let decr ( ? by = 1 ) ( { score } as desc ) = let score = score - by in if score < 0 then None else Some { desc with score } let max t1 t2 = match t1 , t2 with | None , None -> None | None , _ -> t2 | ...
module Make ( A : sig val cache : Levenshtein . StringWithHashtbl . cache let case_check s1 s2 = match s1 , s2 with | " " , " " -> true | " " , _ | _ , " " -> false | _ -> let case s = match String . unsafe_get s 0 with | ' a ' . . ' z ' | ' ' # -> 0 | ' A ' . . ' Z ' -> 1 | _ -> 2 in case s1 = case s2 let match_name_l...
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ " Version " , [ " 2014 - 11 - 01 " ] ; " Action " , [ " Sign " ] ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( SignRequest . to...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " SignResponse " ( snd xml ) ) ( Xml . member " SignResult " ) in try Util . or_error ( Util . option_bind resp SignResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well forme...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if List . mem var errors && match Errors_internal . to_http_code var with | Some var -> var = code | None -> true then Some var else None | None -> None
type t = | Neg | Zero | Pos
let t_of_sexp = ( let _tp_loc = " sign0 . ml . t " in function | Ppx_sexp_conv_lib . Sexp . Atom ( " neg " | " Neg " ) -> Neg | Ppx_sexp_conv_lib . Sexp . Atom ( " zero " | " Zero " ) -> Zero | Ppx_sexp_conv_lib . Sexp . Atom ( " pos " | " Pos " ) -> Pos | Ppx_sexp_conv_lib . Sexp . List ( Ppx_sexp_conv_lib . Sexp . At...
let sexp_of_t = ( function | Neg -> Ppx_sexp_conv_lib . Sexp . Atom " Neg " | Zero -> Ppx_sexp_conv_lib . Sexp . Atom " Zero " | Pos -> Ppx_sexp_conv_lib . Sexp . Atom " Pos " : t -> Ppx_sexp_conv_lib . Sexp . t ) ; ;
let compare = ( Ppx_compare_lib . polymorphic_compare : t -> t -> int )
let ( hash_fold_t : Ppx_hash_lib . Std . Hash . state -> t -> Ppx_hash_lib . Std . Hash . state ) = ( fun hsv arg -> match arg with | Neg -> Ppx_hash_lib . Std . Hash . fold_int hsv 0 | Zero -> Ppx_hash_lib . Std . Hash . fold_int hsv 1 | Pos -> Ppx_hash_lib . Std . Hash . fold_int hsv 2 : Ppx_hash_lib . Std . Hash . s...
let ( hash : t -> Ppx_hash_lib . Std . Hash . hash_value ) = let func arg = Ppx_hash_lib . Std . Hash . get_hash_value ( let hsv = Ppx_hash_lib . Std . Hash . create ( ) in hash_fold_t hsv arg ) in fun x -> func x ; ;
let all = ( [ Neg ; Zero ; Pos ] : t list ) [ @@@ end ]
module Replace_polymorphic_compare = struct let ( < ) ( x : t ) y = Poly . ( < ) x y let ( <= ) ( x : t ) y = Poly . ( <= ) x y let ( <> ) ( x : t ) y = Poly . ( <> ) x y let ( = ) ( x : t ) y = Poly . ( = ) x y let ( > ) ( x : t ) y = Poly . ( > ) x y let ( >= ) ( x : t ) y = Poly . ( >= ) x y let ascending ( x : t ) ...
let of_string s = t_of_sexp ( sexp_of_string s )
let to_string t = string_of_sexp ( sexp_of_t t )
let to_int = function | Neg -> - 1 | Zero -> 0 | Pos -> 1 ; ;
let of_int n = if n < 0 then Neg else if n = 0 then Zero else Pos
let signaled = ref false
let counter = ref 0
let sighandler _ = signaled := true
let print_message delay c = while ( not ! signaled ) && ( ! counter <= 20 ) do incr counter ; print_char c ; flush stdout ; Thread . delay delay done
let _ = ignore ( Sys . signal Sys . sigint ( Sys . Signal_handle sighandler ) ) ; let th1 = Thread . create ( print_message 0 . 6666666666 ) ' a ' in print_message 1 . 0 ' b ' ; Thread . join th1 ; if ! signaled then begin print_string " Got ctrl - C , exiting " ; print_newline ( ) ; exit 0 end else begin print_string ...
let handle_multimedia_keys device = OBus_signal . connect ( Hal_device . condition device ) >|= ( E . map_p ( fun ( action , key ) -> let % lwt ( ) = printlf " from Hal : action % S on key % S " ! action key in let % lwt ( ) = printlf " the signal come from the device % S " ( OBus_path . to_string ( Hal_device . udi de...
let ( ) = Lwt_main . run begin let % lwt session = OBus_bus . session ( ) in let % lwt ( ) = OBus_signal . connect ( OBus_bus . name_owner_changed session ) >|= ( E . map_p ( fun ( name , old_owner , new_owner ) -> printlf " from D - Bus : the owner of the name % S changed : % S -> % S " name old_owner new_owner ) ) >|...
module Public_key_hash = struct include Tezos_crypto . Signature . Public_key_hash module Set = struct include Stdlib . Set . Make ( Tezos_crypto . Signature . Public_key_hash ) let encoding = Data_encoding . conv elements ( fun l -> List . fold_left ( fun m x -> add x m ) empty l ) Data_encoding . ( list Tezos_crypto ...
type api = { service : string ; version : string ; }
module Time = struct module C = CalendarLib . Calendar module P = CalendarLib . Printer . Calendar let date_yymmdd = P . sprint " % Y % m % d " let date_time = P . sprint " % Y % m % dT % H % M % SZ " let now_utc ( ) = C . ( now ( ) |> to_gmt ) end
module Hash = struct open Cstruct open Nocrypto . Hash . SHA256 let hex_encode s = Hex . of_string s |> fun ( ` Hex hstr ) -> hstr let sha256 ? k str = match k with | None -> to_string @@ digest ( of_string str ) | Some k -> to_string @@ hmac ~ key ( : of_string k ) ( of_string str ) let hex_hash ? k str = hex_encode (...
module Signature = struct let retrieve_key s = try Unix . getenv s with Not_found -> failwith @@ Printf . sprintf " Environment variable % s not found . " s let iam_secret = retrieve_key " AWS_SECRET_KEY " let iam_access = retrieve_key " AWS_ACCESS_KEY " let signing_algorithm = " AWS4 - HMAC - SHA256 " let v4_req = " a...
let realize_headers ? acl meth uri body_str api region = let open Signature in let acl_str = " x - amz - acl " in let signed_headers = [ " content - type " ; " host " ; " x - amz - date " ] |> let timestamp = Time . now_utc ( ) in let host = match Uri . host uri with | Some h -> h | None -> " ec2 . amazonaws . com " in...
type item = | Error of string | IncludedFieldModule of Name . t * Name . t * PathName . t | IncludedFieldType of Name . t * Name . t * PathName . t | IncludedFieldValue of Name . t * Name . t list * Type . t * Name . t * PathName . t | Module of Name . t * t | ModuleAlias of Name . t * PathName . t | ModuleFreeVar of M...
let rec string_of_included_module_typ_aux ( module_typ : Typedtree . module_type ) module_type : string = match module_typ . mty_desc with | Tmty_ident ( path , _ ) _ | Tmty_alias ( path , _ ) _ -> Path . last path | Tmty_signature _ -> " signature " | Tmty_functor _ -> " functor " | Tmty_with ( module_typ , _ ) _ -> s...
let string_of_included_module_typ ( module_typ : Typedtree . module_type ) module_type : string = " Included_ " ^ string_of_included_module_typ_aux module_typ
let of_types_signature ( signature : Types . signature ) signature : t Monad . t = signature |> Monad . List . map ( function | Types . Sig_value ( ident , { val_type ; _ } , _ ) _ -> let * name = Name . of_ident true ident in Type . of_typ_expr true Name . Map . empty val_type >>= fun ( typ , _ , _ ) _ -> let typ_vars...
let of_first_class_types_signature ( module_name : Name . t ) t ( signature_path : Path . t ) t ( signature : Types . signature ) signature ( final_env : Env . t ) t : t Monad . t = let get_field_path_name name = PathName . of_path_and_name_with_convert signature_path name in set_env final_env ( signature |> Monad . Li...
let rec of_signature ( signature : Typedtree . signature ) signature : t Monad . t = let of_signature_item ( signature_item : Typedtree . signature_item ) signature_item ( final_env : Env . t ) t : item list Monad . t = set_env signature_item . sig_env ( set_loc signature_item . sig_loc ( match signature_item . sig_des...
let to_coq_included_field ( module_name : Name . t ) t ( field_name : PathName . t ) t : SmartPrint . t = MixedPath . to_coq ( MixedPath . Access ( PathName . of_name [ ] module_name , [ field_name ] ) )
let rec to_coq ( signature : t ) t : SmartPrint . t = let to_coq_item ( signature_item : item ) item : SmartPrint . t = match signature_item with | Error message -> ( ) " " !^ | IncludedFieldModule ( name , module_name , field_name ) field_name -> let field = to_coq_included_field module_name field_name in nest ( " !^ ...
let test_check_callables 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 ( callable : typing . Callable [ [ str ] , None ] ) -> None : callable ( 1 ) } | [ " Incompatible parameter ty...
let test_check_function_redirects context = assert_type_errors ~ context { | def foo ( a : float ) -> float : return abs ( a ) } | [ ]
let test_check_function_parameters_with_backups context = assert_type_errors ~ context " ( 1 ) . __add__ ( 1 ) " [ ] ; assert_type_errors ~ context " ( 1 ) . __add__ ( 1j ) " [ ] ; assert_type_errors ~ context " ( 1 ) . __add__ ( 1 . 0 ) " [ ] ; assert_type_errors ~ context " ( 1 ) . __iadd__ ( 1 . 0 ) " [ ]
let test_check_function_parameters context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | from builtins import int_to_int def foo ( ) -> None : int_to_int ( 1 ) } | [ ] ; assert_type_errors { | from builtins impo...
let test_check_function_parameter_errors context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import str_float_to_int class Foo : attribute : str = " " def foo ( input : Foo ) -> None : str_float_to_int ( input . attribute , input . undefined ) } | [ " Incompatible par...
let test_check_function_overloads context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import overload , Union class Foo : @ overload def derp ( self , x : int ) -> int : pass @ overload def derp ( self , x : str ) -> str : pass def derp ( self , x : Union [ int , str ] ...
let test_check_constructor_overloads context = assert_type_errors ~ context { | import typing class Class : @ typing . overload def __init__ ( self , i : int ) -> None : . . . @ typing . overload def __init__ ( self , s : str ) -> None : . . . def construct ( ) -> None : Class ( 1 ) Class ( ' asdf ' ) } | [ " Missing o...
let test_check_variable_arguments context = let assert_type_errors = assert_type_errors ~ context in let assert_strict_type_errors = assert_strict_type_errors ~ context in assert_type_errors { | import typing class C ( typing . Iterable [ int ] ) : . . . def f ( a : int , b : int ) -> None : pass def g ( c : C ) -> Non...
let test_check_variable_restrictions context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import variable_restricted_identity def f ( x : str ) -> int : return variable_restricted_identity ( x ) } | [ " Incompatible return type [ 7 ] : Expected ` int ` but got ` str ` ...
let test_check_keyword_arguments 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 : int , y : str ) -> None : pass def bar ( x : typing . Dict [ str , str ] ) -> None : test = foo ...
let test_check_named_arguments context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import str_float_to_int def bar ( ) -> int : return str_float_to_int ( i " " , = f = 2 . 0 ) + str_float_to_int ( f = 1 . 0 , i " = bar " ) } | [ ] ; assert_type_errors { | class Bar : ...
let test_check_literals context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing from typing import overload from typing_extensions import Literal import typing_extensions @ typing . overload def foo ( x : typing_extensions . Literal [ " give_me_int " , " also_give_me_int ...
let ( ) = " signatureSelection " >::: [ " check_callables " >:: test_check_callables ; " check_function_redirects " >:: test_check_function_redirects ; " check_function_parameters_with_backups " >:: test_check_function_parameters_with_backups ; " check_function_parameters " >:: test_check_function_parameters ; " check_...
type mismatch = { actual : Type . t ; expected : Type . t ; name : Identifier . t option ; position : int ; }
type invalid_argument = { expression : Expression . t option ; annotation : Type . t ; }
type missing_argument = | Named of Identifier . t | PositionalOnly of int
type mismatch_with_unpackable_type = | NotUnpackableType of invalid_argument | CannotConcatenate of Type . OrderedTypes . t list | ConstraintFailure of Type . OrderedTypes . t
type mismatch_reason = | Mismatch of mismatch Node . t | MismatchWithUnpackableType of { variable : Type . OrderedTypes . t ; mismatch : mismatch_with_unpackable_type ; }
let location_insensitive_compare_mismatch_reason left right = match left , right with | Mismatch { Node . value = left ; _ } , Mismatch { Node . value = right ; _ } -> [ % compare : mismatch ] left right | _ -> [ % compare : mismatch_reason ] left right
type reason = | AbstractClassInstantiation of { class_name : Reference . t ; abstract_methods : string list ; } | CallingParameterVariadicTypeVariable | InvalidKeywordArgument of invalid_argument Node . t | InvalidVariableArgument of invalid_argument Node . t | Mismatches of mismatch_reason list | MissingArgument of mi...
let location_insensitive_compare_reason left right = match left , right with | Mismatches left_list , Mismatches right_list -> List . compare location_insensitive_compare_mismatch_reason left_list right_list | _ -> [ % compare : reason ] left right
let equal_reason = [ % compare . equal : reason ]
type closest = { closest_return_annotation : Type . t ; reason : reason option ; }
let equal_closest ( left : closest ) ( right : closest ) = Type . equal left . closest_return_annotation right . closest_return_annotation && Option . equal [ % compare . equal : reason ] left . reason right . reason
type instantiated_return_annotation = | Found of { selected_return_annotation : Type . t } | NotFound of closest
module TypeShape = struct type t = { nb_function_parameters : int ; nb_type_applications_result : int } let rec get_nb_function_parameters ( typ : Types . type_expr ) type_expr : int * Types . type_expr = match typ . desc with | Tarrow ( _ , _ , typ2 , _ ) _ -> let nb_function_parameters , result_typ = get_nb_function_...
type t = { high_level : Name . Set . t ; precise : TypeShape . t option Name . Map . t option ; }
let of_signature_without_hash ( attributes : Typedtree . attributes option ) option ( signature : Types . signature ) signature : t = let shape_list = signature |> List . filter_map ( fun item -> match item with | Types . Sig_value ( ident , typ , _ ) _ -> let typ_shape = TypeShape . of_typ typ . val_type in Some ( Nam...
module Hash = Hashtbl . Make ( struct type t = Types . signature let equal = ( == ) let hash = Hashtbl . hash end ) end
let signature_shape_hash : t Hash . t = Hash . create 12
let of_signature ( attributes : Parsetree . attributes option ) option ( signature : Types . signature ) signature : t = match Hash . find_opt signature_shape_hash signature with | None -> let shape = of_signature_without_hash attributes signature in Hash . add signature_shape_hash signature shape ; shape | Some shape ...
let are_equal ( shape1 : t ) t ( shape2 : t ) t : bool = Name . Set . equal shape1 . high_level shape2 . high_level && match ( shape1 . precise , shape2 . precise ) precise with | Some precise1 , Some precise2 -> Name . Map . equal ( = ) precise1 precise2 | _ -> true
let pretty_print ( shape : t ) t : SmartPrint . t = shape . high_level |> Name . Set . elements |> List . sort compare |> OCaml . list Name . to_coq
type sig_item = { src : Types . signature_item ; post_ghosts : Types . signature_item list ; }
let flatten x = x . src :: x . post_ghosts
type core_rec_group = | Not_rec of sig_item | Rec_group of sig_item list
let rec_items = function | Not_rec x -> [ x ] | Rec_group x -> x
type rec_group = { pre_ghosts : Types . signature_item list ; group : core_rec_group }
let next_group = function | [ ] -> None | src :: q -> let ghosts , q = match src with | Types . Sig_class _ -> begin match q with | ct :: t :: ht :: q -> [ ct ; t ; ht ] , q | _ -> assert false end | Types . Sig_class_type _ -> begin match q with | t :: ht :: q -> [ t ; ht ] , q | _ -> assert false end | Types . ( Sig_...
let recursive_sigitem = function | Types . Sig_type ( ident , _ , rs , _ ) | Types . Sig_class ( ident , _ , rs , _ ) | Types . Sig_class_type ( ident , _ , rs , _ ) | Types . Sig_module ( ident , _ , _ , rs , _ ) -> Some ( ident , rs ) | Types . ( Sig_value _ | Sig_modtype _ | Sig_typext _ ) -> None
let next x = let cons_group pre group q = let group = Rec_group ( List . rev group ) in Some ( { pre_ghosts = List . rev pre ; group } , q ) in let rec not_in_group pre l = match next_group l with | None -> assert ( pre [ ] ) ; = None | Some ( elt , q ) -> match recursive_sigitem elt . src with | Some ( id , _ ) when B...
let seq l = Seq . unfold next l