text
stringlengths
0
601k
let get_symmetries accuracy state = Public_data . AccuracyMap . find_option accuracy state . symmetric_sites
let set_symmetries accuracy partition state = { state with symmetric_sites = Public_data . AccuracyMap . add accuracy partition state . symmetric_sites }
let info_to_agent ( agent_name , pos , agent_id ) = { Public_data . agent_id = Ckappa_sig . int_of_agent_name agent_id ; Public_data . agent_ast = agent_name ; Public_data . agent_position = pos }
module Make ( RPC_client : RPC_client . S ) ( S : sig val default : Uri . t val authenticate : Signature . Public_key_hash . t list -> Bytes . t -> Signature . t tzresult Lwt . t val logger : RPC_client . logger end ) = struct let scheme = scheme let title = " Built - in tezos - signer using remote wallet . " let descr...
let make_sk sk = Client_keys . make_sk_uri ( Uri . make ~ scheme ~ path ( : Signature . Secret_key . to_b58check sk ) ( ) )
let make_pk pk = Client_keys . make_pk_uri ( Uri . make ~ scheme ~ path ( : Signature . Public_key . to_b58check pk ) ( ) )
let read_base_uri_from_env ( ) = match ( Sys . getenv_opt " TEZOS_SIGNER_UNIX_PATH " , Sys . getenv_opt " TEZOS_SIGNER_TCP_HOST " , Sys . getenv_opt " TEZOS_SIGNER_HTTP_HOST " , Sys . getenv_opt " TEZOS_SIGNER_HTTPS_HOST " ) with | ( None , None , None , None ) -> return_none | ( Some path , None , None , None ) -> ret...
type error += Invalid_remote_signer of string
let ( ) = register_error_kind ` Branch ~ id " : invalid_remote_signer " ~ title " : Unexpected URI fot remote signer " ~ description " : The provided remote signer is invalid . " ~ pp ( : fun ppf s -> Format . fprintf ppf " [ @< v 0 > Value ' % s ' is not a valid URI for a remote signer . , @\ Supported URIs for remote...
let parse_base_uri s = match Uri . of_string s with | exception Invalid_argument msg -> error_with " Malformed URI : % s " msg | exception Not_found -> error_with " Malformed URI " | uri -> ( match Uri . scheme uri with | Some " http " -> Ok uri | Some " https " -> Ok uri | Some " tcp " -> Ok uri | Some " unix " -> Ok ...
let parse_base_uri s = parse_base_uri s |> record_trace ( Invalid_remote_signer s ) |> Lwt . return
let state_dir = Current . state_dir id
let sync_pool = Current . Pool . create ~ label " : ssh " 1
let sync ~ job t = let open Lwt . Syntax in let remote_folder = Fmt . str " % s @@% s :% s " / ( Config . Ssh . user t ) ( Config . Ssh . host t ) ( Config . Ssh . storage_folder t ) in let switch = Current . Switch . create ~ label " : ssh " ( ) in Lwt . finalize ( fun ( ) -> Current . Job . log job " Synchronizing re...
type build_result = Ok of digest | Failed
type cache_entry = ( digest * build_result ) option
let digest = function | None -> " none " | Some ( k , Failed ) -> " failed " - ^ k | Some ( k , Ok digest ) -> " ok " - ^ k ^ " " - ^ digest
let pp f = function | None -> Fmt . pf f " none " | Some ( _ , Failed ) -> Fmt . pf f " failed " | Some ( _ , Ok digest ) -> Fmt . pf f " ok -> % s " digest
let folder_digest_exn = function Some ( _ , Ok digest ) -> digest | _ -> raise Not_found
let key_file path = Fpath . ( state_dir // add_ext " . key " path )
let digest_file path = Fpath . ( state_dir // add_ext " . sha256 " path )
let get _ path = Bos . OS . File . read ( key_file path ) |> Result . to_option |> Option . map ( fun key -> ( key , match Bos . OS . File . read ( digest_file path ) with | Ok v -> Ok ( String . trim v ) | Error _ -> Failed ) )
let cmd_write_key key paths = let pp_write_key f folder = Fmt . pf f " mkdir - p cache /% a && echo ' % s ' > cache /% a . key " Fpath . pp ( Fpath . parent folder ) key Fpath . pp folder in Fmt . ( str " % a " ( list ~ sep ( : any " && " ) pp_write_key ) paths )
let cmd_compute_sha256 paths = let pp_compute_digest f folder = Fmt . pf f " ( mkdir - p cache /% a && ( find % a / - type f - exec sha256sum { } ; ) \\ | sort - k 2 | sha256sum > \ cache /% a . sha256 ) " Fpath . pp ( Fpath . parent folder ) Fpath . pp folder Fpath . pp folder in Fmt . ( str " % a " ( list ~ sep ( : a...
let cmd_sync_folder t = Fmt . str " rsync - avz cache % s :% s " / ( Config . Ssh . host t ) ( Config . Ssh . storage_folder t )
module Op = struct type t = No_context let pp f _ = Fmt . pf f " remote cache " module Key = struct type t = Config . Ssh . t let digest = Config . Ssh . digest end module Value = Current . Unit let auto_cancel = true let id = id let build No_context job ssh = let open Lwt . Syntax in let * ( ) = Current . Job . start ...
module Cache = Current_cache . Make ( Op )
let v ssh = let open Current . Syntax in let + _ = Current . primitive ~ info ( : Current . component " remote cache pull " ) ( Cache . get No_context ) ( Current . return ssh ) in ssh
type ' a node = { mutable next : ' a node option ; mutable prev : ' a node option ; data : ' a ; mutable queue : ' a t option } { tail : ' a node ; head : ' a node } | Empty | Non_empty of ' a non_empty
let create ( ) = ref Empty
let is_empty t = ! t = Empty
let push ( type a ) ( t : a t ) ( a : a ) = let node prev = { next = None ; prev ; data = a ; queue = Some t } in match ! t with | Empty -> let node = node None in t := Non_empty { tail = node ; head = node } ; node | Non_empty ne -> let node = node ( Some ne . tail ) in assert ( ne . tail . next = None ) ; ne . tail ....
let pop ( type a ) ( t : a t ) : a option = match ! t with | Empty -> None | Non_empty ne -> let node = ne . head in if Option . is_none node . next then t := Empty else t := Non_empty { ne with head = Option . value_exn node . next } ; node . prev <- None ; node . next <- None ; node . queue <- None ; Some node . data
let remove node = if Option . is_some node . queue then ( ( match ( node . next , node . prev ) with | None , None -> Option . value_exn node . queue := Empty | _ , _ -> ( ( match node . next with | None -> ( ) | Some next -> next . prev <- node . prev ) ; match node . prev with | None -> ( ) | Some prev -> prev . next...
let print_all q f = while not ( Q . is_empty q ) do let elem = Option . value_exn ( Q . pop q ) in printf " elem : % s \ n " ( f elem ) done
let add_all q xs = List . iter xs ~ f ( : fun x -> ignore ( Q . push q x ) ) let q = Q . create ( ) in printf " new queue is empty : % b " ( Q . is_empty q ) ; [ % expect { | new queue is empty : true } ] | let q = Q . create ( ) in let ( _ : int Q . node ) = Q . push q 100 in printf " empty : % b \ n " ( Q . is_empty ...
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 - 10 - 31 " ] ) ; ( " Action " , [ " RemoveFromGlobalCluster " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query ...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " RemoveFromGlobalClusterResponse " ( snd xml ) ) ( Xml . member " RemoveFromGlobalClusterResult " ) in try Util . or_error ( Util . option_bind resp RemoveFromGlobalClusterResult . parse ) ( let open Error in Bad...
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
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 - 10 - 31 " ] ) ; ( " Action " , [ " RemoveSourceIdentifierFromSubscription " ] ) ] ( Util . drop_empty ( Uri . query_of_e...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " RemoveSourceIdentifierFromSubscriptionResponse " ( snd xml ) ) ( Xml . member " RemoveSourceIdentifierFromSubscriptionResult " ) in try Util . or_error ( Util . option_bind resp RemoveSourceIdentifierFromSubscri...
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
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 " , [ " 2015 - 02 - 02 " ] ) ; ( " Action " , [ " RemoveTagsFromResource " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query ....
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " RemoveTagsFromResourceResponse " ( snd xml ) ) ( Xml . member " RemoveTagsFromResourceResult " ) in try Util . or_error ( Util . option_bind resp TagListMessage . parse ) ( let open Error in BadResponse { body ;...
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
let ( ) = Pass_wrapper . register ~ pass_name
let rewrite_one_function_decl ( ~ function_decl : Flambda . function_declaration ) ~ back_free_vars ~ specialised_args = let params_for_equal_free_vars = List . fold_left ( fun subst param -> match Variable . Map . find param specialised_args with | exception Not_found -> subst | ( spec_to : Flambda . specialised_to ) ...
let rewrite_one_set_of_closures ( set_of_closures : Flambda . set_of_closures ) = let back_free_vars = Variable . Map . fold ( fun var ( outside_var : Flambda . specialised_to ) map -> let set = match Variable . Map . find outside_var . var map with | exception Not_found -> Variable . Set . singleton var | set -> Varia...
let run ~ ppf_dump set_of_closures = Pass_wrapper . with_dump ~ ppf_dump ~ pass_name ~ input : set_of_closures ~ print_input : Flambda . print_set_of_closures ~ print_output : Flambda . print_set_of_closures ~ f ( : fun ( ) -> rewrite_one_set_of_closures set_of_closures )
let eq_lx_last_m_m_x lx m x ty eq_list = ( eqmake ( EQeq ( pmake ( Evarpat ( lx ) ) ty , emake ( Elast ( m ) ) ty ) ) ) :: ( eqmake ( EQeq ( pmake ( Evarpat ( m ) ) ty , emake ( Elocal ( x ) ) ty ) ) ) :: eq_list
let add x ty sort ( env , new_env , subst , eq_list ) = let lx = Zident . fresh " l " in let m = Zident . fresh " m " in Env . add x { t_typ = ty ; t_sort = Deftypes . value } env , Env . add lx { t_typ = ty ; t_sort = Deftypes . value } ( Env . add m { t_typ = ty ; t_sort = sort } new_env ) , Env . add x lx subst , eq...
let valenv subst b_env = let last x ( { t_typ = ty ; t_sort = sort } as entry ) ( env , new_env , subst , eq_list ) = match sort with | Smem { m_previous = true } -> add x ty sort ( env , new_env , subst , eq_list ) | Smem { m_previous = false } -> Env . add x { entry with t_sort = Sval } env , new_env , subst , eq_lis...
let extend_block ( { b_locals = l_list } as b ) env eq_list = { b with b_locals = ( Zaux . make_local env eq_list ) :: l_list }
let present_handlers subst scondpat body p_h_list = List . map ( fun ( { p_cond = scpat ; p_body = b ; p_env = p_env } as handler ) -> let p_env , new_env , subst , eq_list = valenv subst p_env in let b = body subst b new_env eq_list in { handler with p_cond = scondpat subst scpat ; p_env = p_env ; p_body = b } ) p_h_l...
let rec exp subst ( { e_desc } as e ) = let e_desc = match e_desc with | Elast ( x ) -> begin try Elocal ( Env . find x subst ) with Not_found -> e_desc end | Elocal _ | Econst _ | Econstr0 _ | Eglobal _ -> e_desc | Etuple ( e_list ) -> Etuple ( List . map ( exp subst ) e_list ) | Econstr1 ( c , e_list ) -> Econstr1 ( ...
let implementation impl = match impl . desc with | Eopen _ | Etypedecl _ | Econstdecl _ | Efundecl ( _ , { f_kind = S | A } ) -> impl | Efundecl ( n , ( { f_body = e ; f_env = f_env } as body ) ) -> let f_env , new_env , subst , eq_list = valenv Env . empty f_env in let e = exp subst e in let e = Zaux . make_let new_en...
let implementation_list impl_list = Zmisc . iter implementation impl_list
let ( ) = Clflags . all_passes := pass_name :: ! Clflags . all_passes
let rename_var var = Variable . rename var ~ current_compilation_unit ( : Compilation_unit . get_current_exn ( ) )
let remove_params unused ( fun_decl : Flambda . function_declaration ) ~ new_fun_var = let unused_params , used_params = List . partition ( fun v -> Variable . Set . mem ( Parameter . var v ) unused ) fun_decl . params in let unused_params = List . filter ( fun v -> Variable . Set . mem ( Parameter . var v ) fun_decl ....
let make_stub unused var ( fun_decl : Flambda . function_declaration ) ~ specialised_args ~ additional_specialised_args = let renamed = rename_var var in let args ' = List . map ( fun param -> param , Parameter . rename param ) fun_decl . params in let used_args ' = List . filter ( fun ( param , _ ) -> not ( Variable ....
let separate_unused_arguments ~ only_specialised ~ backend ( ~ set_of_closures : Flambda . set_of_closures ) = let function_decls = set_of_closures . function_decls in let unused = Invariant_params . unused_arguments ~ backend function_decls in let non_stub_arguments = Variable . Map . fold ( fun _ ( decl : Flambda . f...
let should_split_only_specialised_args ( fun_decls : Flambda . function_declarations ) ~ backend = if not ! Clflags . remove_unused_arguments then begin true end else begin let no_recursive_functions = Variable . Set . is_empty ( Find_recursive_functions . in_function_declarations fun_decls ~ backend ) in let number_of...
let separate_unused_arguments_in_set_of_closures set_of_closures ~ backend = let dump = Clflags . dumped_pass pass_name in let only_specialised = should_split_only_specialised_args set_of_closures . Flambda . function_decls ~ backend in match separate_unused_arguments ~ only_specialised ~ backend ~ set_of_closures with...
let separate_unused_arguments_in_closures_expr tree ~ backend = let aux_named ( named : Flambda . named ) : Flambda . named = match named with | Set_of_closures set_of_closures -> begin let only_specialised = should_split_only_specialised_args set_of_closures . function_decls ~ backend in match separate_unused_argument...
let separate_unused_arguments_in_closures program ~ backend = Flambda_iterators . map_exprs_at_toplevel_of_program program ~ f ( : fun expr -> separate_unused_arguments_in_closures_expr expr ~ backend )
let remove_unused_closure_variables ~ remove_direct_call_surrogates program = let used_vars_within_closure , used_closure_ids = let used = Var_within_closure . Tbl . create 13 in let used_fun = Closure_id . Tbl . create 13 in let aux_named ( named : Flambda . named ) = match named with | Project_closure { set_of_closur...
let dependency ( expr : Flambda . t ) = Flambda . free_symbols expr
let constant_dependencies ( const : Flambda . constant_defining_value ) = let closure_dependencies ( set_of_closures : Flambda . set_of_closures ) = Flambda . free_symbols_named ( Set_of_closures set_of_closures ) in match const with | Allocated_const _ -> Symbol . Set . empty | Block ( _ , fields ) -> let symbol_field...
let let_rec_dep defs dep = let add_deps l dep = List . fold_left ( fun dep ( sym , sym_dep ) -> if Symbol . Set . mem sym dep then Symbol . Set . union dep sym_dep else dep ) dep l in let defs_deps = List . map ( fun ( sym , def ) -> sym , constant_dependencies def ) defs in let rec fixpoint dep = let new_dep = add_dep...
let rec loop ( program : Flambda . program_body ) : Flambda . program_body * Symbol . Set . t = match program with | Let_symbol ( sym , def , program ) -> let program , dep = loop program in if Symbol . Set . mem sym dep then Let_symbol ( sym , def , program ) , Symbol . Set . union dep ( constant_dependencies def ) el...
let remove_unused_program_constructs ( program : Flambda . program ) = { program with program_body = fst ( loop program . program_body ) ; }
let writefile filename contents = let oc = open_out_bin filename in output_string oc contents ; close_out oc
let readfile filename = let ic = open_in_bin filename in let sz = in_channel_length ic in let contents = really_input_string ic sz in close_in ic ; contents
let safe_remove filename = try Sys . remove filename with Sys_error _ -> ( )
let testrename f1 f2 contents = try Unix . rename f1 f2 ; if readfile f2 <> contents then print_string " wrong contents " ! else if Sys . file_exists f1 then print_string " initial file still exists " ! else print_string " passed " with Unix . Unix_error ( err , _ , _ ) -> print_string " Unix_error exception : " ; prin...
let testfailure f1 f2 = try Unix . rename f1 f2 ; print_string " should fail but doesn ' t " ! with Unix . Unix_error _ -> print_string " fails as expected "
let _ = let f1 = " file1 . dat " and f2 = " file2 . dat " in safe_remove f1 ; safe_remove f2 ; print_string " Rename to nonexisting file : " ; writefile f1 " abc " ; testrename f1 f2 " abc " ; print_newline ( ) ; print_string " Rename to existing file : " ; writefile f1 " def " ; writefile f2 " xyz " ; testrename f1 f2...
type t = { mutable immediate : int array ; mutable delayed : ( t * t ) option ; mutable is_identity : bool ; mutable dsts : Mods . IntSet . t }
let empty ( ) = { immediate = [ ] ; || delayed = None ; is_identity = true ; dsts = Mods . IntSet . empty }
let dummy = empty ( )
let identity l = let max = List . fold_left max 0 l in let immediate = Array . make ( succ max ) special_val in let ( ) = List . iter ( fun x -> immediate . ( x ) <- x ) l in { immediate ; delayed = None ; is_identity = true ; dsts = List . fold_left ( fun out x -> Mods . IntSet . add x out ) Mods . IntSet . empty l }
let is_identity i = i . is_identity
let rec compute k i = let v = i . immediate . ( k ) in if v <> special_val then v else match i . delayed with | None -> special_val | Some ( x , y ) -> if k >= Array . length x . immediate then special_val else let v ' = compute k x in if v ' = special_val then special_val else let v ' ' = compute v ' y in let o = if v...
let force i = if i . delayed <> None then let ( ) = Array . iteri ( fun k _ -> ignore ( compute k i ) ) i . immediate in i . delayed <- None
let to_list i = let ( ) = force i in Tools . array_fold_lefti ( fun i acc v -> if v <> special_val then ( i , v ) :: acc else acc ) [ ] i . immediate |> List . rev
let image i = i . dsts
let unsafe_functionnal_add x y i = let l = max ( Array . length i . immediate ) ( x + 1 ) in let immediate = Array . make l special_val in let ( ) = Array . blit i . immediate 0 immediate 0 ( Array . length i . immediate ) in let ( ) = immediate . ( x ) <- y in { immediate ; delayed = i . delayed ; is_identity = i . is...
let add ~ debugMode x y i = let not_ok = debugMode && x < Array . length i . immediate && i . immediate . ( x ) <> special_val in if not_ok then raise Clashing else let i ' = unsafe_functionnal_add x y i in if i . dsts == i ' . dsts then None else Some i '
let unsafe_imperative_add x y i = let ( ) = let l = Array . length i . immediate in if x >= l then let immediate = Array . make ( succ x ) special_val in let ( ) = Array . blit i . immediate 0 immediate 0 l in let ( ) = immediate . ( x ) <- y in i . immediate <- immediate else i . immediate . ( x ) <- y in let ( ) = i ...
let imperative_add ~ debugMode x y i = let not_ok = debugMode && x < Array . length i . immediate && i . immediate . ( x ) <> special_val in if not_ok then raise Clashing else let origin = i . dsts in let ( ) = unsafe_imperative_add x y i in not ( i . dsts == origin )
let rec cyclic_permutation_from_identity max id subst pre = function | _ when pre = id -> unsafe_imperative_add pre max subst | [ ] -> assert false | h :: t -> let ( ) = unsafe_imperative_add pre h subst in cyclic_permutation_from_identity max id subst h t
let cyclic_permutation_from_list ~ stop_at = function | [ ] -> failwith " Renaming . cyclic_permutation_from_list " | h :: t -> let out = empty ( ) in let ( ) = cyclic_permutation_from_identity h stop_at out h t in out
let mem x i = x < Array . length i . immediate && compute x i <> special_val
let fold f i acc = let ( ) = force i in Tools . array_fold_lefti ( fun i acc v -> if v = special_val then acc else f i v acc ) acc i . immediate
let apply ~ debugMode i x = if not i . is_identity || debugMode then let c = compute x i in if c = special_val then raise Undefined else c else x
let compose ~ debugMode extensible i i ' = if not i . is_identity || extensible || debugMode then { immediate = Array . make ( Array . length i . immediate ) special_val ; delayed = Some ( i , i ' ) ; is_identity = i . is_identity && i ' . is_identity ; dsts = Mods . IntSet . fold ( fun v ' set -> let v ' ' = compute v...
let inverse i = if i . is_identity then i else let out = empty ( ) in let ( ) = force i in let ( ) = Array . iteri ( fun x y -> if y <> special_val then if y < Array . length out . immediate && out . immediate . ( y ) <> special_val then raise NotBijective else unsafe_imperative_add y x out ) i . immediate in out
let compare i i ' = let ( ) = force i in let ( ) = force i ' in Tools . array_compare Mods . int_compare i . immediate i ' . immediate
let equal i i ' = ( compare i i ' ) = 0