text
stringlengths
0
601k
let min_elt i = let l = Array . length i . immediate in let rec aux_min_elt k = if k >= l then None else let o = compute k i in if o = special_val then aux_min_elt ( succ k ) else Some ( k , o ) in aux_min_elt 0
let print f i = let ( ) = force i in ignore ( Tools . array_fold_lefti ( fun src b dst -> if src <> dst && dst <> special_val then let ( ) = Format . fprintf f " % t % i ->% i " ( if b then Pp . comma else Pp . empty ) src dst in true else b ) false i . immediate )
let print_full f i = let ( ) = force i in Format . fprintf f " [ ( @% a ) ] " @ ( Pp . array Pp . comma ( fun src f dst -> if dst <> special_val then if src <> dst then Format . fprintf f " % i ->% i " src dst else Format . pp_print_int f src ) ) i . immediate
let to_yojson i = let ( ) = force i in ` List ( Tools . array_fold_lefti ( fun src acc dst -> if dst <> special_val then ` List [ ` Int src ; ` Int dst ] :: acc else acc ) [ ] i . immediate )
let of_yojson = function | ` List l -> let out = empty ( ) in let ( ) = List . iter ( function | ` List [ ` Int src ; ` Int dst ] as x -> if not ( imperative_add ~ debugMode : false src dst out ) then raise ( Yojson . Basic . Util . Type_error ( " Incorrect renaming item " , x ) ) | x -> raise ( Yojson . Basic . Util ....
let html_to_string html = let b = Buffer . create 1000 in let ppf = Format . formatter_of_buffer b in H . pp ( ) ppf html ; Format . pp_print_flush ppf ( ) ; Buffer . contents b
let html_elt_to_string html = let b = Buffer . create 1000 in let ppf = Format . formatter_of_buffer b in H . pp_elt ( ) ppf html ; Format . pp_print_flush ppf ( ) ; Buffer . contents b < head > < title > OCamlOScope . 2 server </ title > < meta charset " = UTF - 8 " > < link rel " = stylesheet " href " = style . css "...
let spans ? a s = H . span ? a [ H . pcdata s ]
let query_form pspec ( v : string ) = let open Query . PackageSpec in let packs = match pspec with | All_but xs -> xs | Just xs -> xs | Vanilla xs -> xs in let mk_option v p = H . a_value v :: if p pspec then [ H . a_selected ( ) ] else [ ] in [ % html { | < div class " = query " > < span class " = logo " > OC &# x1f44...
let path_last = function | Outcometree . Oide_dot ( _ , s ) -> Outcometree . Oide_ident s | x -> x
let hpath p = spans ~ a [ : H . a_class [ " path " ] ] & Format . sprintf " % a " Xoprint . print_ident p
let fsignature_item orgdoc ( i : Data . DB . item ) = let open Data . DB in let open Sig in let open Outcometree in let module M = Sigext . Print . Make ( struct let simplif_path = Sigext . Print . path_simplifier i . kind i . path end ) in let string_of_type ty = Format . sprintf " % a " ! Xoprint . out_type ( M . sim...
let print_summary ( sum : ( Data . alias * int * ( int * Data . DB . item * ' trace1 * ' trace2 ) list list ) list ) = let group i ( alias , _dist , xss ) = let nonaliased , aliased = partition ( fun ( _ , i , _ , _ ) -> i . Data . DB . alias = None ) & flatten xss in let orgdoc = match filter_map ( fun ( _ , i , _ , _...
let document_of_odocl ~ syntax input = Odoc_file . load input >>= fun unit -> match unit . content with | Odoc_file . Page_content odoctree -> Ok ( Renderer . document_of_page ~ syntax odoctree ) | Unit_content odoctree -> Ok ( Renderer . document_of_compilation_unit ~ syntax odoctree )
let document_of_input ~ resolver ~ warnings_options ~ syntax input = let output = Fs . File . ( set_ext " . odocl " input ) in Odoc_link . from_odoc ~ resolver ~ warnings_options input output >>= function | ` Page page -> Ok ( Renderer . document_of_page ~ syntax page ) | ` Module m -> Ok ( Renderer . document_of_compi...
let render_document renderer ~ output : root_dir ~ extra_suffix ~ extra odoctree = let pages = renderer . Renderer . render extra odoctree in Renderer . traverse pages ~ f ( : fun filename content -> let filename = match extra_suffix with | Some s -> Fpath . add_ext s filename | None -> filename in let filename = Fpath...
let render_odoc ~ resolver ~ warnings_options ~ syntax ~ renderer ~ output extra file = document_of_input ~ resolver ~ warnings_options ~ syntax file >>= render_document renderer ~ output ~ extra_suffix : None ~ extra
let generate_odoc ~ syntax ~ renderer ~ output ~ extra_suffix extra file = document_of_odocl ~ syntax file >>= render_document renderer ~ output ~ extra_suffix ~ extra
let targets_odoc ~ resolver ~ warnings_options ~ syntax ~ renderer ~ output : root_dir ~ extra odoctree = let doc = if Fpath . get_ext odoctree = " . odoc " then document_of_input ~ resolver ~ warnings_options ~ syntax odoctree else document_of_odocl ~ syntax odoctree in doc >>= fun odoctree -> let pages = renderer . R...
module Line = struct type t = { timestamp : Time_ns . t ; command : string } let parse line = match String . split line ~ on ' : ' with | timestamp :: command -> let timestamp = timestamp |> Int63 . of_string |> Time_ns . of_int63_ns_since_epoch in { timestamp ; command = String . concat ~ sep " : " command } | _ -> ra...
let process_lines lines ~ test_name = let clock = let start_time = match lines with | [ ] -> Time_ns . epoch | line :: _ -> ( Line . parse line ) . timestamp in Profile . Private . Clock . create ~ now : start_time in Profile . Private . clock := clock ; let ( _ : Line . t option ) = profile Sync ( lazy [ % sexp ( test...
let command = Command . async ~ summary : { | } | ( let % map_open . Command ( ) = return ( ) and file = anon ( " file " %: string ) and test_name = flag " - test - name " ( required string ) ~ doc " : NAME the name of the test we ' re profiling " and output_file = flag " - output - file " ( required string ) ~ doc " :...
let ( ) = Command_unix . run command
module PP = Prim_parser . Make ( COMBI . Parser . Make ( COMBI . Parser . OptionBase ) )
let parse p s = match p % s with | Some ( t , [ ] ) -> t | _ -> raise ParseError
let parse ' p s = match p s with | Some ( t , [ ] ) -> t | _ -> raise ParseError
module MkRepl ( T : Pure . THEORY ) = struct module S = Statics . Make ( T ) open S open Lang_parser . Make ( PP ) ( T ) open Pure open Dynamics let prgm = prgm let fold_decs = List . fold_left ( fun ( g , d ) ( x , e ) -> let e = bind_up e in let t = synthtype ( g , d ) e in let e ' = beta d e in print_endline ( x ^ "...
let read_file f = let ch = open_in f in let s = really_input_string ch ( in_channel_length ch ) in close_in ch ; s
let parse_theory f = let s = read_file f in match pragmas % s with | None -> raise ( Failure " Missing SORTS , AXIOMS , or RULES " ) | Some ( ( sorts , axioms , rules ) , rest ) -> let theory = ( module struct let sorts = sorts let axioms = axioms let rules = rules end : Pure . THEORY ) in ( theory , rest )
let _ = if Array . length Sys . argv < 2 then print_endline " Please provide file with SORTS , AXIOMS , RULES and optional definitions " else let file = Sys . argv . ( 1 ) in let ( theory , txt ) = parse_theory file in let module T = ( val theory : Pure . THEORY ) in let module Repl = MkRepl ( T ) in try let ds = parse...
module StringMap = Map . Make ( String )
let regexp = Str . regexp " [ ] " %%^%*%%
let current_dir = Sys . getcwd ( )
let guess_version ( ) = let prefix = " proto_ " in let rec loop dir = let dirname = Filename . basename dir in let x = String . length prefix in let n = String . length dirname in if n >= x && String . sub dirname 0 x = prefix then String . sub dirname x ( n - x ) else let updir = Filename . dirname dir in if updir = d...
let warning_message = { | ; ; ; } |
let replace ~ template ~ destination vars = let inch = open_in template in let outch = open_out destination in output_string outch warning_message ; try while true do let line = input_line inch in let line = Str . global_substitute regexp ( fun s -> let matched = Str . matched_string s in let var = String . sub matched...
let module_name ( c : Protocol . component ) = String . capitalize_ascii c . name
let sources_name ( c : Protocol . component ) = let name = String . uncapitalize_ascii c . name in match c . interface with | None -> Printf . sprintf " % s . ml " name | Some _ -> Printf . sprintf " % s . mli % s . ml " name name
let process ~ template ~ destination ( protocol : Protocol . t ) lib_version hash check_hash = let version = String . concat " " - ( String . split_on_char ' _ ' lib_version ) in let vars = StringMap . empty |> StringMap . add " VERSION " version |> StringMap . add " LIB_VERSION " lib_version |> StringMap . add " ENV_V...
let read_proto destination final_protocol_file = let source_dir = if Filename . is_relative destination then Filename . concat current_dir ( Filename . dirname destination ) else Filename . dirname destination in Lwt_main . run ( Lwt_utils_unix . read_file final_protocol_file >>= fun final_protocol -> let final_protoco...
let main ( ) = let template = Sys . argv . ( 1 ) in let destination = Sys . argv . ( 2 ) in let final_protocol_file = Sys . argv . ( 3 ) in let version = try Sys . argv . ( 4 ) with Invalid_argument _ -> guess_version ( ) in let ( hash , proto , check_hash ) = read_proto destination final_protocol_file in process ~ tem...
let ( ) = main ( )
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 " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " ReplaceIamInstanceProfileAssociation " ] ) ] ( Util . drop_empty ( Uri . query_of_enc...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " ReplaceIamInstanceProfileAssociationResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp ReplaceIamInstanceProfileAssociationResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find wel...
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
module SimpleMap = CCMap . Make ( String )
module PairMap = CCMap . Make ( struct type t = string * string let compare = compare end )
type t = { keywords : string SimpleMap . t ; types : string SimpleMap . t ; cast : string PairMap . t ; op_to_fun : string PairMap . t ; op_to_op : string PairMap . t ; fun_to_fun : string PairMap . t ; array_init : string SimpleMap . t ; array_copy : string SimpleMap . t ; real_string : ( float -> string ) SimpleMap ....
let global_replacement_map : t SimpleMap . t ref = ref SimpleMap . empty
let registerReplacements ( name : string ) ( t : t ) : unit = global_replacement_map := SimpleMap . add name t ! global_replacement_map
let getReplacements ( name : string ) : t = SimpleMap . find name ! global_replacement_map
let takeSecond _ ( opt1 : ' a option ) ( opt2 : ' a option ) : ' a option = match opt1 , opt2 with | _ , Some _ -> opt2 | _ -> opt1
let extendReplacements ( first : t ) ( second : t ) : t = { keywords = SimpleMap . merge takeSecond first . keywords second . keywords ; types = SimpleMap . merge takeSecond first . types second . types ; cast = PairMap . merge takeSecond first . cast second . cast ; op_to_fun = PairMap . merge takeSecond first . op_to...
let empty = { keywords = SimpleMap . empty ; types = SimpleMap . empty ; cast = PairMap . empty ; op_to_fun = PairMap . empty ; op_to_op = PairMap . empty ; fun_to_fun = PairMap . empty ; array_init = SimpleMap . empty ; array_copy = SimpleMap . empty ; real_string = SimpleMap . empty }
let getKeyword ( t : t ) ( name : string ) : string = match SimpleMap . get name t . keywords with | Some new_keyword -> new_keyword | None -> name
let getType ( t : t ) ( name : string ) : string = match SimpleMap . get name t . types with | Some new_type -> new_type | None -> name
let getCast ( t : t ) ( from_t : string ) ( to_t : string ) : string = let to_tt = getType t to_t in let from_tt = getType t from_t in match PairMap . get ( from_tt , to_tt ) t . cast with | Some cast -> cast | None -> to_tt
let getFunctionForOperator ( t : t ) ( op : string ) ( typ : string ) : string option = let typ_t = getType t typ in PairMap . get ( op , typ_t ) t . op_to_fun
let getOperator ( t : t ) ( op : string ) ( typ : string ) : string = let typ_t = getType t typ in match PairMap . get ( op , typ_t ) t . op_to_op with | Some new_op -> new_op | None -> op
let getArrayInit ( t : t ) ( name : string ) : string option = SimpleMap . get name t . array_init
let getArrayCopy ( t : t ) ( name : string ) : string option = SimpleMap . get name t . array_copy
let getFunction ( t : t ) ( op : string ) ( typ : string ) : string = let typ_t = getType t typ in match PairMap . get ( op , typ_t ) t . fun_to_fun with | Some new_op -> new_op | None -> op
let getRealToString ( t : t ) ( value : float ) ( typ : string ) : string = let typ_t = getType t typ in match SimpleMap . get typ_t t . real_string with | Some fn -> fn value | None -> Float . to_string value
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 " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " ReplaceNetworkAclAssociation " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Q...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " ReplaceNetworkAclAssociationResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp ReplaceNetworkAclAssociationResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed Replace...
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 " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " ReplaceRouteTableAssociation " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Q...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " ReplaceRouteTableAssociationResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp ReplaceRouteTableAssociationResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed Replace...
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 " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " ReplaceTransitGatewayRoute " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Que...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " ReplaceTransitGatewayRouteResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp ReplaceTransitGatewayRouteResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed ReplaceTran...
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 node_client = Manager_operations . node_client = { node : Node . t ; client : Client . t ; }
type two_nodes = Manager_operations . two_nodes = { main : node_client ; observer : node_client ; }
let check_applied ~ __LOC__ nodes inject = Memchecks . with_applied_checks ~ __LOC__ nodes ~ expected_statuses [ ] : ~ bake : false inject
let check_branch_delayed ~ __LOC__ nodes inject = Memchecks . with_branch_delayed_checks ~ __LOC__ ~ bake : false nodes inject
let check_refused ~ __LOC__ nodes inject = Memchecks . with_refused_checks ~ __LOC__ ~ bake : false nodes inject
let op_is_applied ~ __LOC__ nodes opH = Lwt_list . iter_s ( fun client -> let * mempool = Mempool . get_mempool client in Memchecks . check_operation_is_in_mempool ~ __LOC__ ` Applied mempool opH ; unit ) [ nodes . main . client ; nodes . observer . client ]
let op_is_outdated ~ __LOC__ nodes opH = Lwt_list . iter_s ( fun client -> let * mempool = Mempool . get_mempool client in Memchecks . check_operation_is_in_mempool ~ __LOC__ ` Outdated mempool opH ; unit ) [ nodes . main . client ; nodes . observer . client ]
let minimal_replacement_fee = let factor = Q . make ( Z . of_int 105 ) ( Z . of_int 100 ) in fun fee -> let r = Q . mul ( Q . of_int fee ) factor in Z . cdiv ( Q . num r ) ( Q . den r ) |> Z . to_int
let replacement_fee = minimal_replacement_fee default_fee
type op_info = { fee : int ; gas : int ; amount : int ; get_counter : Client . t -> int option Lwt . t ; }
let default_op = { fee = default_fee ; gas = default_gas ; amount = default_amount ; get_counter = ( fun _ -> Lwt . return_none ) ; }
let replacement_op = { default_op with fee = replacement_fee }
let get_counter ( ? contract = default_source ) client = let * counter = RPC . Contracts . get_counter ~ contract_id : contract . Account . public_key_hash client in Lwt . return @@ JSON . as_int counter
let mk_batch client op_data size = let * counter = op_data . get_counter client in let * counter = match counter with None -> get_counter client | Some c -> Lwt . return c in let rec batch_rec nb acc = if nb < 0 then Lwt . return [ ] else if nb = 0 then Lwt . return acc else let * op = Operation . mk_transfer ~ source ...
let replacement_test_helper ~ title ~ __LOC__ ~ op1 ( ? size1 = 1 ) ~ op2 ( ? size2 = 1 ) ~ incheck1 ~ incheck2 ~ postcheck2 ? op3 ( ? size3 = 1 ) ? incheck3 ? postcheck3 ( ) = Protocol . register_test ~ __FILE__ ~ title ~ tags [ " : replace " ; " fee " ; " manager " ] @@ fun protocol -> let * nodes = Helpers . init ~ ...
let identical_operations = replacement_test_helper ~ __LOC__ ~ title " : Injecting the same operation twice " ~ op1 : default_op ~ op2 : default_op ~ incheck1 : check_applied ~ incheck2 : check_applied ~ postcheck2 ( : fun _nodes h1 h2 -> assert ( h1 = h2 ) ; unit ) ( )
let same_gas_and_fees_but_different_ops = replacement_test_helper ~ __LOC__ ~ title " : Inject two different operations with same gas and fee " ~ op1 : default_op ~ op2 { : default_op with amount = default_amount + 1 } ~ incheck1 : check_applied ~ incheck2 : check_branch_delayed ~ postcheck2 ( : fun nodes h1 _h2 -> op_...
let replacement_fees_below_threshold = replacement_test_helper ~ __LOC__ ~ title " : Second op ' s fees are below threshold by 1 mutez " ~ op1 : default_op ~ op2 { : replacement_op with fee = replacement_op . fee - 1 } ~ incheck1 : check_applied ~ incheck2 : check_branch_delayed ~ postcheck2 ( : fun nodes h1 _h2 -> op_...
let replacement_fees_equal_to_threshold = replacement_test_helper ~ __LOC__ ~ title " : Second op ' s fees are equal to replacement fees threshold " ~ op1 : default_op ~ op2 : replacement_op ~ incheck1 : check_applied ~ incheck2 : check_applied ~ postcheck2 ( : fun nodes h1 _h2 -> op_is_outdated ~ __LOC__ nodes h1 ) ( ...
let replacement_fees_above_threshold = replacement_test_helper ~ __LOC__ ~ title " : Second op ' s fees are above replacement fees threshold by 1 mutez " ~ op1 : default_op ~ op2 { : replacement_op with fee = replacement_op . fee + 1 } ~ incheck1 : check_applied ~ incheck2 : check_applied ~ postcheck2 ( : fun nodes h1 ...
let third_operation_fees_below_replacement_threshold = let op2 = { replacement_op with fee = replacement_op . fee + 1 } in replacement_test_helper ~ __LOC__ ~ title " : Replace a replacement requires bumping fees again " ~ op1 : default_op ~ op2 ~ incheck1 : check_applied ~ incheck2 : check_applied ~ postcheck2 ( : fun...
let third_operation_fees_equal_to_replacement_threshold = let op2 = { replacement_op with fee = replacement_op . fee + 1 } in replacement_test_helper ~ __LOC__ ~ title " : Replace a replacement op with enough fees " ~ op1 : default_op ~ op2 ~ incheck1 : check_applied ~ incheck2 : check_applied ~ postcheck2 ( : fun node...
let replacement_fees_equal_to_threshold_but_gas_increased = replacement_test_helper ~ __LOC__ ~ title " : Second op ' s fees are equal to replacement fees . But gas increased " ~ op1 : default_op ~ op2 { : replacement_op with gas = replacement_op . gas + 1 } ~ incheck1 : check_applied ~ incheck2 : check_branch_delayed ...
let replacement_fees_below_threshold_even_if_gas_is_decreased = let op2 = replacement_op in replacement_test_helper ~ __LOC__ ~ title : " Second op ' s gas descreased by 1 , but still no enough replacement fees " ~ op1 : default_op ~ op2 { : op2 with fee = op2 . fee - 1 ; gas = op2 . gas - 1 } ~ incheck1 : check_applie...
let fees_of_second_op_below_fees_of_first_one = let op1 = { default_op with fee = 50_000 ; gas = 100_000 } in let op2 = { op1 with fee = op1 . fee ; gas = op1 . gas / 100 } in replacement_test_helper ~ __LOC__ ~ title " : Op2 ' s gas / fee is more important , but fees are not higher than max " ~ op1 ~ op2 ~ incheck1 : ...
let cannot_replace_with_an_op_having_diffrent_counter = let get_counter client = let * counter = get_counter client in Lwt . return_some @@ ( counter + 100 ) in let op2 = { default_op with fee = 100 * default_op . fee ; get_counter } in replacement_test_helper ~ __LOC__ ~ title " : Much more fees in second op , but cou...
let cannot_replace_a_non_applied_operation = let get_counter client = let * counter = get_counter client in Lwt . return_some @@ ( counter + 100 ) in let op1 = { default_op with get_counter } in replacement_test_helper ~ __LOC__ ~ title " : First operation not applied , second one applied with default fees " ~ op1 ~ op...
let replace_simple_op_with_a_batched_low_fees = replacement_test_helper ~ __LOC__ ~ title " : Gas limit doubled in batch . More fees needed " ~ op1 : default_op ~ op2 { : default_op with fee = ( replacement_fee / 2 ) + 1 } ~ size2 : 2 ~ incheck1 : check_applied ~ incheck2 : check_branch_delayed ~ postcheck2 ( : fun nod...