text
stringlengths
0
601k
let save_table_sqlite filename = hh_save_table_sqlite filename " hh_save_table_keys_sqlite "
let save_table_keys_sqlite filename keys = hh_save_table_keys_sqlite filename keys
let load_table_sqlite filename verify = hh_load_table_sqlite filename verify
let init_done ( ) = ( )
type table_stats = { nonempty_slots : int ; used_slots : int ; slots : int ; }
let dep_stats ( ) = let used = dep_used_slots ( ) in { nonempty_slots = used ; used_slots = used ; slots = dep_slots ( ) ; }
let hash_stats ( ) = let used_slots , nonempty_slots = hash_used_slots ( ) in { nonempty_slots ; used_slots ; slots = hash_slots ( ) ; }
let should_collect ( effort : [ ` gentle | ` aggressive | ` always_TEST ] ) = let overhead = match effort with | ` always_TEST -> 1 . 0 | ` aggressive -> 1 . 2 | ` gentle -> 2 . 0 in let used = heap_size ( ) in let wasted = wasted_heap_size ( ) in let reachable = used - wasted in used >= truncate ( ( float reachable ) ...
let collect ( effort : [ ` gentle | ` aggressive | ` always_TEST ] ) = if should_collect effort then begin hh_collect ( ) ; end
let is_heap_overflow ( ) = hh_check_heap_overflow ( )
module HeapSize = struct let rec traverse ( ( visited : ISet . t ) , acc ) r = if Obj . is_block r then begin let p : int = Obj . magic r in if ISet . mem p visited then ( visited , acc ) else begin let visited ' = ISet . add p visited in let n = Obj . size r in let acc ' = acc + 1 + n in if Obj . tag r < Obj . no_scan...
module type KeyType = sig type t val to_string : t -> string val from_string : string -> t val compare : t -> t -> int end
module type ValueType = sig type t val prefix : Prefix . t val description : string end
module type Key = sig type userkey type t type old type md5 val make : Prefix . t -> userkey -> t val make_old : Prefix . t -> userkey -> old val to_old : t -> old val new_from_old : old -> t val md5 : t -> md5 val md5_old : old -> md5 val string_of_md5 : md5 -> string end
module KeyFunctor ( KeyType : KeyType ) : Key with type userkey = KeyType . t = struct type userkey = KeyType . t type t = string type old = string type md5 = string let old_prefix = " old_ " let make prefix x = Prefix . make_key prefix ( KeyType . to_string x ) let make_old prefix x = old_prefix ^ Prefix . make_key pr...
module Raw ( Key : Key ) ( Value : ValueType ) : sig val add : Key . md5 -> Value . t -> unit val mem : Key . md5 -> bool val get : Key . md5 -> Value . t val remove : Key . md5 -> unit val move : Key . md5 -> Key . md5 -> unit module LocalChanges : sig val has_local_changes : unit -> bool val push_stack : unit -> unit...
module New : functor ( Key : Key ) -> functor ( Value : ValueType ) -> sig val add : Key . t -> Value . t -> unit val get : Key . t -> Value . t option val get_exn : Key . t -> Value . t val remove : Key . t -> unit val mem : Key . t -> bool val oldify : Key . t -> unit module Raw : module type of Raw ( Key ) ( Value )...
module Old : functor ( Key : Key ) -> functor ( Value : ValueType ) -> functor ( _ : module type of Raw ( Key ) ( Value ) ) -> sig val get : Key . old -> Value . t option val remove : Key . old -> unit val mem : Key . old -> bool val revive : Key . old -> unit end = functor ( Key : Key ) -> functor ( Value : ValueType ...
module TableTypes = struct module type S = sig type key type value module KeySet : Set . S with type elt = key module KeyMap : MyMap . S with type key = key end module Make ( KeyType : KeyType ) ( Value : ValueType ) = struct module Key = KeyFunctor ( KeyType ) module KeySet = Set . Make ( KeyType ) module KeyMap = MyM...
module NoCache = struct module type S = sig include TableTypes . S val add : key -> value -> unit val get : key -> value option val get_exn : key -> value val mem : key -> bool val get_batch : KeySet . t -> value option KeyMap . t val remove_batch : KeySet . t -> unit val get_old : key -> value option val mem_old : key...
module type ConfigType = sig type value val capacity : int end
module type CacheType = sig type key type value val add : key -> value -> unit val get : key -> value option val remove : key -> unit val clear : unit -> unit val get_size : unit -> int end
module FreqCache ( Key : sig type t end ) ( Config : ConfigType ) : CacheType with type key := Key . t and type value := Config . value = struct type value = Config . value let ( cache : ( Key . t , int ref * value ) Hashtbl . t ) = Hashtbl . create ( 2 * Config . capacity ) let size = ref 0 let get_size ( ) = ! size l...
module OrderedCache ( Key : sig type t end ) ( Config : ConfigType ) : CacheType with type key := Key . t and type value := Config . value = struct let ( cache : ( Key . t , Config . value ) Hashtbl . t ) = Hashtbl . create Config . capacity let queue = Queue . create ( ) let size = ref 0 let get_size ( ) = ! size let ...
let invalidate_callback_list = ref [ ]
let invalidate_caches ( ) = List . iter ! invalidate_callback_list ~ f : begin fun callback -> callback ( ) end
module LocalCache ( KeyType : KeyType ) ( Value : ValueType ) = struct type key = KeyType . t type value = Value . t module ConfValue = struct type value = Value . t let capacity = 1000 end module L1 = OrderedCache ( KeyType ) ( ConfValue ) module L2 = FreqCache ( KeyType ) ( ConfValue ) let add x y = L1 . add x y ; L2...
module WithCache = struct module type S = sig include NoCache . S val write_around : key -> value -> unit val get_no_cache : key -> value option end module Make ( KeyType : KeyType ) ( Value : ValueType ) = struct module Direct = NoCache . Make ( KeyType ) ( Value ) type key = Direct . key type value = Direct . value m...
module FirstClass = struct module TupleKey ( Key : KeyType ) = struct type t = int * Key . t let to_string ( id , key ) = Format . asprintf " % d :% s " id ( Key . to_string key ) let from_string string_key = let split = String . split_on_char ' ' : string_key in match split with | [ ] -> failwith ( Format . asprintf "...
module IntKey = struct type t = int let to_string = Int . to_string let compare = Int . compare let from_string = Core . Int . of_string end
module StringKey = struct type t = string let to_string = Fn . id let compare = String . compare let from_string x = x end
module ReferenceKey = struct type t = Reference . t [ @@ deriving compare , sexp ] let to_string = Reference . show let from_string name = Reference . create name end
module AttributeTableKey = struct module T = struct type t = { include_generated_attributes : bool ; accessed_via_metaclass : bool ; name : Type . Primitive . t ; } [ @@ deriving compare , sexp , hash , show ] end include T module Set = Set . Make ( T ) include Hashable . Make ( T ) let to_string key = sexp_of_t key |>...
module ParseAnnotationKey = struct type type_validation_policy = | NoValidation | ValidatePrimitives | ValidatePrimitivesAndTypeParameters [ @@ deriving compare , sexp , hash , show ] module T = struct type t = { validation : type_validation_policy ; expression : Expression . t ; } [ @@ deriving compare , sexp , hash ,...
type dependency = | TypeCheckDefine of Reference . t | AliasRegister of Reference . t | ClassConnect of Type . Primitive . t | RegisterClassMetadata of Type . Primitive . t | UndecoratedFunction of Reference . t | AnnotateGlobal of Reference . t | AnnotateGlobalLocation of Reference . t | FromEmptyStub of Reference . t...
module In = struct type key = dependency [ @@ deriving compare , sexp ] module KeySet = Caml . Set . Make ( struct type t = dependency [ @@ deriving compare , sexp ] end ) type registered = { hash : DependencyTrackedMemory . EncodedDependency . t ; key : key ; } [ @@ deriving compare , sexp ] module RegisteredSet = Cam...
module DependencyKey = struct include In include DependencyTrackedMemory . DependencyKey . Make ( In ) end
module LocationKey = struct type t = Location . t let to_string key = Location . sexp_of_t key |> Sexp . to_string let compare = Location . compare let from_string sexp_string = Sexp . of_string sexp_string |> Location . t_of_sexp end
module StringKey = struct type t = string let to_string = Fn . id let compare = String . compare let from_string = Fn . id end
module StringValue = struct type t = string let prefix = Prefix . make ( ) let description = " string for testing " end
module StringStringTable = SharedMemory . FirstClass . WithCache . Make ( StringKey ) ( StringValue )
let test_first_class _ = let table0 = StringStringTable . create ( ) in assert_equal ~ cmp ( : Option . equal String . equal ) ( StringStringTable . get table0 " x " ) None ; StringStringTable . add table0 " x " " x0 " ; assert_equal ~ cmp ( : Option . equal String . equal ) ( StringStringTable . get table0 " x " ) ( S...
let ( ) = " shared_memory " >::: [ " first_class " >:: test_first_class ; ] |> Test . run
module Rich_text = struct module Underline = struct type t = | Single | Double | Single_accounting | Double_accounting | None [ @@ deriving sexp_of ] let of_string = function | " single " -> Single | " double " -> Double | " singleAccounting " -> Single_accounting | " doubleAccounting " -> Double_accounting | " none " ...
module String_item = struct type t = Rich_text . t list [ @@ deriving sexp_of ] let to_string t = List . map t ~ f : Rich_text . text |> String . concat ~ sep " " : let of_xml = function | Xml . Element ( " si " , _ , children ) -> List . filter_map children ~ f : Rich_text . of_xml |> Option . some | _ -> None end
type t = String_item . t list [ @@ deriving sexp_of ]
let to_string_array t = List . map t ~ f : String_item . to_string |> List . to_array
let of_xml = expect_element " sst " ( fun _ -> List . filter_map ~ f : String_item . of_xml )
let float_equal x y = if x = 0 . && y = 0 . then ( copysign 1 . x = copysign 1 . y ) else if classify_float x = FP_nan && classify_float y = FP_nan then ( true ) else ( x = y )
let array_equal eq tbl1 tbl2 = let len1 = Array . length tbl1 in let len2 = Array . length tbl2 in len1 = len2 && ( try for i = 0 to len1 - 1 do if not ( eq tbl1 . ( i ) tbl2 . ( i ) ) then raise Exit ; done ; true with Exit -> false )
let float_array_equal tbl1 tbl2 = array_equal float_equal tbl1 tbl2
let value_equal = let open T in let rec loop depth v1 v2 = if v1 == v2 then true else if depth > 1000 then false else match v1 , v2 with | Int i1 , Int i2 -> i1 = i2 | Int32 i1 , Int32 i2 -> i1 = i2 | Int64 i1 , Int64 i2 -> i1 = i2 | Nativeint i1 , Nativeint i2 -> i1 = i2 | Float x1 , Float x2 -> float_equal x1 x2 | Fl...
let block_equal ( tag1 , tbl1 ) ( tag2 , tbl2 ) = tag1 = tag2 && array_equal value_equal tbl1 tbl2
module FloatArrayHashtbl = Hashtbl . Make ( struct type t = float array let equal = float_array_equal let hash = Hashtbl . hash end )
module BlockHashtbl = Hashtbl . Make ( struct type t = int * T . value array let equal = block_equal let hash = Hashtbl . hash end )
module ClosureHashtbl = Hashtbl . Make ( struct type t = T . code_ptr array * T . value array let equal = block_equal let hash = Hashtbl . hash end )
type ' a t = { int32_cache : ( int32 , ' a ) Hashtbl . t ; int64_cache : ( int64 , ' a ) Hashtbl . t ; nativeint_cache : ( nativeint , ' a ) Hashtbl . t ; float_array_cache_imm : ' a FloatArrayHashtbl . t ; float_array_cache_mut : ( float array , ' a ) Qhtbl . t ; bytes_cache_imm : ( bytes , ' a ) Hashtbl . t ; bytes_c...
let create ( ) = let int32_cache = Hashtbl . create 16 in let int64_cache = Hashtbl . create 16 in let nativeint_cache = Hashtbl . create 16 in let float_array_cache_imm = FloatArrayHashtbl . create 16 in let float_array_cache_mut = Qhtbl . create ( ) in let bytes_cache_imm = Hashtbl . create 16 in let bytes_cache_mut ...
let value_mutability value = let open T in let qhtbl = Qhtbl . create ( ) in let rec loop value = if Qhtbl . mem qhtbl value then false else ( Qhtbl . put qhtbl value ( ) ; match value with | Int _ | Int32 _ | Int64 _ | Nativeint _ | Float _ | CodePtr _ -> false | Float_array ( mut , _ ) | Bytes ( mut , _ ) | Object ( ...
let find_int32 sh i = Hashtbl . find sh . int32_cache i
let find_int64 sh i = Hashtbl . find sh . int64_cache i
let find_nativeint sh i = Hashtbl . find sh . nativeint_cache i
let find_float_array sh mut xs = match mut with | T . Immutable -> FloatArrayHashtbl . find sh . float_array_cache_imm xs | T . Mutable -> Qhtbl . find sh . float_array_cache_mut xs
let find_bytes sh mut b = match mut with | T . Immutable -> Hashtbl . find sh . bytes_cache_imm b | T . Mutable -> Qhtbl . find sh . bytes_cache_mut b
let find_block sh mut tag b = match value_mutability ( T . Block ( mut , ref tag , b ) ) with | T . Immutable -> BlockHashtbl . find sh . block_cache_imm ( tag , b ) | T . Mutable -> Qhtbl . find sh . block_cache_mut b
let find_closure sh cp vs = match value_mutability ( T . Closure { T . ofs = 0 ; ptrs = cp ; env = vs } ) with | T . Immutable -> ClosureHashtbl . find sh . closure_cache_imm ( cp , vs ) | T . Mutable -> Qhtbl . find ( Qhtbl . find sh . closure_cache_mut cp ) vs
let put_int32 sh i x = assert ( not ( Hashtbl . mem sh . int32_cache i ) ) ; Hashtbl . add sh . int32_cache i x
let put_int64 sh i x = assert ( not ( Hashtbl . mem sh . int64_cache i ) ) ; Hashtbl . add sh . int64_cache i x
let put_nativeint sh i x = assert ( not ( Hashtbl . mem sh . nativeint_cache i ) ) ; Hashtbl . add sh . nativeint_cache i x
let put_float_array sh mut fs x = match mut with | T . Immutable -> assert ( not ( FloatArrayHashtbl . mem sh . float_array_cache_imm fs ) ) ; FloatArrayHashtbl . add sh . float_array_cache_imm fs x | T . Mutable -> Qhtbl . put sh . float_array_cache_mut fs x
let put_bytes sh mut b x = match mut with | T . Immutable -> assert ( not ( Hashtbl . mem sh . bytes_cache_imm b ) ) ; Hashtbl . add sh . bytes_cache_imm b x | T . Mutable -> Qhtbl . put sh . bytes_cache_mut b x
let put_block sh mut tag b x = match value_mutability ( T . Block ( mut , ref tag , b ) ) with | T . Immutable -> assert ( not ( BlockHashtbl . mem sh . block_cache_imm ( tag , b ) ) ) ; BlockHashtbl . add sh . block_cache_imm ( tag , b ) x | T . Mutable -> Qhtbl . put sh . block_cache_mut b x
let put_closure sh cp vs x = match value_mutability ( T . Closure { T . ofs = 0 ; ptrs = cp ; env = vs } ) with | T . Immutable -> assert ( not ( ClosureHashtbl . mem sh . closure_cache_imm ( cp , vs ) ) ) ; ClosureHashtbl . add sh . closure_cache_imm ( cp , vs ) x | T . Mutable -> ( let sub_qhtbl = match Qhtbl . find ...
let update_constant_for_sharing sharing_symbol_tbl const : Flambda . constant_defining_value = let substitute_symbol sym = match Symbol . Tbl . find sharing_symbol_tbl sym with | exception Not_found -> sym | symbol -> symbol in match ( const : Flambda . constant_defining_value ) with | Allocated_const _ -> const | Bloc...
let cannot_share ( const : Flambda . constant_defining_value ) = match const with | Allocated_const ( ( String _ ) | ( Float_array _ ) ) -> true | Allocated_const _ | Set_of_closures _ | Project_closure _ | Block _ -> false
let share_definition constant_to_symbol_tbl sharing_symbol_tbl symbol def ( end_symbols : Symbol . Set . t ) = let def = update_constant_for_sharing sharing_symbol_tbl def in if cannot_share def || Symbol . Set . mem symbol end_symbols then Some def else begin match Constant_defining_value . Tbl . find constant_to_symb...
let rec end_symbols ( program : Flambda . program_body ) : Symbol . Set . t = match program with | End symbol -> symbol | Let_symbol ( _ , _ , program ) | Let_rec_symbol ( _ , program ) | Initialize_symbol ( _ , _ , _ , program ) | Effect ( _ , program ) -> end_symbols program
let share_constants ( program : Flambda . program ) = let end_symbols = end_symbols program . program_body in let sharing_symbol_tbl = Symbol . Tbl . create 42 in let constant_to_symbol_tbl = Constant_defining_value . Tbl . create 42 in let rec loop ( program : Flambda . program_body ) : Flambda . program_body = match ...
let ( ) ~! = Jg_memo . fast ~ f : Str . regexp val mutable history = ( [ ] : ' a list ) val mutable count = 0 method empty = history = [ ] method add s = count <- 0 ; history <- s :: history method previous = let s = List . nth history count in count <- ( count + 1 ) mod List . length history ; s method next = let l = ...
let dump_handle ( h : Unix . file_descr ) = let obj = Obj . repr h in if Obj . is_int obj || Obj . tag obj <> Obj . custom_tag then invalid_arg " Shell . dump_handle " ; Nativeint . format " % x " ( Obj . obj obj )
let protect f x = try f x with _ -> ( )
let is_win32 = Sys . os_type = " Win32 "
let use_sigpipe = is_win32 let ( in2 , out1 ) = Unix . pipe ( ) and ( in1 , out2 ) = Unix . pipe ( ) and ( err1 , err2 ) = Unix . pipe ( ) and ( sig2 , sig1 ) = Unix . pipe ( ) in val pid = let env = if use_sigpipe then let sigdef = " CAMLSIGPIPE " = ^ dump_handle sig2 in Array . append env [ | sigdef ] | else env in U...
let shells : ( string * shell ) list ref = ref [ ]
let kill_all ( ) = List . iter ! shells ~ f ( : fun ( _ , sh ) -> if sh # alive then sh # kill ) ; shells := [ ]
let get_all ( ) = let all = List . filter ! shells ~ f ( : fun ( _ , sh ) -> sh # alive ) in shells := all ; all
let may_exec_unix prog = try Unix . access prog ~ perm [ : Unix . X_OK ] ; prog with Unix . Unix_error _ -> " "
let may_exec_win prog = let has_ext = List . exists ~ f ( : Filename . check_suffix prog ) [ " exe " ; " com " ; " bat " ] in if has_ext then may_exec_unix prog else List . fold_left [ prog " . ^ bat " ; prog " . ^ exe " ; prog " . ^ com " ] ~ init " " : ~ f ( : fun res prog -> if res = " " then may_exec_unix prog else...
let may_exec = if is_win32 then may_exec_win else may_exec_unix
let path_sep = if is_win32 then " ; " else " " :
let warnings = ref " Al "
let program_not_found prog = Jg_message . info ~ title " : Error " ( " Program " " \ ^ prog ^ " " \\ nwas not found in path " )
let protect_arg s = if String . contains s ' ' then " " " \ ^ s ^ " " " \ else s
let f ~ prog ~ title = let progargs = List . filter ~ f ( ( ) :<> " " ) ( Str . split " ~! " prog ) in if progargs = [ ] then ( ) else let prog = List . hd progargs in let path = try Sys . getenv " PATH " with Not_found -> " / bin " ^ path_sep ^ " / usr / bin " in let exec_path = Str . split ~! path_sep path in let exe...
let src = Logs . Src . create " fix . coinbase . shell "
let hb msg = Fix . create ~ fields [ : Field . TestReqID . create msg ] MsgType . Heartbeat
let on_server_msg _w msg = match msg . Fix . typ with | _ -> Deferred . unit
let gen_limit_fields ~ symbol ~ side ~ price ~ qty = let clOrdID = Uuidm . create ` V4 in let price = float_of_string price in let qty = float_of_string qty in let timeInForce = Fixtypes . TimeInForce . GoodTillCancel in new_order_fields ~ side ~ price ~ qty ~ timeInForce ~ symbol clOrdID
let on_client_cmd w words = let words = String . split ~ on ' : ' @@ String . chop_suffix_exn words ~ suffix " :\ n " in match words with | " testreq " :: _ -> Pipe . write w ( testreq ~ testreqid " : a " ) | " order " :: orderID :: _ -> let oid = Option . value_exn ( Uuidm . of_string orderID ) in Pipe . write w ( ord...
let key , secret , passphrase = match String . split ~ on ' ' :: ( Sys . getenv_exn " TOKEN_CBPRO " ) with | [ key ; secret ; passphrase ] -> key , secret , passphrase | _ -> assert false