text
stringlengths
12
786k
type var_info = { used : V . Set . t ; linear : V . Set . t ; assigned : V . Set . t ; closure_environment : V . Set . t ; let_bound_vars_that_can_be_moved : V . Set . t ; }
let ignore_uconstant ( _ : Clambda . uconstant ) = ( )
let ignore_ulambda ( _ : Clambda . ulambda ) = ( )
let ignore_ulambda_list ( _ : Clambda . ulambda list ) = ( )
let ignore_uphantom_defining_expr_option ( _ : Clambda . uphantom_defining_expr option ) = ( )
let ignore_function_label ( _ : Clambda . function_label ) = ( )
let ignore_debuginfo ( _ : Debuginfo . t ) = ( )
let ignore_int ( _ : int ) = ( )
let ignore_var ( _ : V . t ) = ( )
let ignore_var_option ( _ : V . t option ) = ( )
let ignore_primitive ( _ : Clambda_primitives . primitive ) = ( )
let ignore_string ( _ : string ) = ( )
let ignore_int_array ( _ : int array ) = ( )
let ignore_var_with_provenance ( _ : VP . t ) = ( )
let ignore_params_with_value_kind ( _ : ( VP . t * Lambda . value_kind ) list ) = ( )
let ignore_direction_flag ( _ : Asttypes . direction_flag ) = ( )
let ignore_meth_kind ( _ : Lambda . meth_kind ) = ( )
let ignore_value_kind ( _ : Lambda . value_kind ) = ( )
let closure_environment_var ( ufunction : Clambda . ufunction ) = if List . length ufunction . params = ufunction . arity + 1 then let ( env_var , _ ) = List . nth ufunction . params ufunction . arity in assert ( VP . name env_var = " env " ) ; Some env_var else None
let make_var_info ( clam : Clambda . ulambda ) : var_info = let t : int V . Tbl . t = V . Tbl . create 42 in let assigned_vars = ref V . Set . empty in let environment_vars = ref V . Set . empty in let rec loop : Clambda . ulambda -> unit = function | Uvar var -> begin match V . Tbl . find t var with | n -> V . Tbl . replace t var ( n + 1 ) | exception Not_found -> V . Tbl . add t var 1 end | Uconst const -> ignore_uconstant const | Udirect_apply ( label , args , dbg ) -> ignore_function_label label ; List . iter loop args ; ignore_debuginfo dbg | Ugeneric_apply ( func , args , dbg ) -> loop func ; List . iter loop args ; ignore_debuginfo dbg | Uclosure ( functions , captured_variables ) -> List . iter loop captured_variables ; List . iter ( fun ( { Clambda . label ; arity ; params ; return ; body ; dbg ; env ; } as clos ) -> ( match closure_environment_var clos with | None -> ( ) | Some env_var -> environment_vars := V . Set . add ( VP . var env_var ) ! environment_vars ) ; ignore_function_label label ; ignore_int arity ; ignore_params_with_value_kind params ; ignore_value_kind return ; loop body ; ignore_debuginfo dbg ; ignore_var_option env ) functions | Uoffset ( expr , offset ) -> loop expr ; ignore_int offset | Ulet ( _let_kind , _value_kind , _var , def , body ) -> loop def ; loop body | Uphantom_let ( var , defining_expr_opt , body ) -> ignore_var_with_provenance var ; ignore_uphantom_defining_expr_option defining_expr_opt ; loop body | Uletrec ( defs , body ) -> List . iter ( fun ( var , def ) -> ignore_var_with_provenance var ; loop def ) defs ; loop body | Uprim ( prim , args , dbg ) -> ignore_primitive prim ; List . iter loop args ; ignore_debuginfo dbg | Uswitch ( cond , { us_index_consts ; us_actions_consts ; us_index_blocks ; us_actions_blocks } , dbg ) -> loop cond ; ignore_int_array us_index_consts ; Array . iter loop us_actions_consts ; ignore_int_array us_index_blocks ; Array . iter loop us_actions_blocks ; ignore_debuginfo dbg | Ustringswitch ( cond , branches , default ) -> loop cond ; List . iter ( fun ( str , branch ) -> ignore_string str ; loop branch ) branches ; Option . iter loop default | Ustaticfail ( static_exn , args ) -> ignore_int static_exn ; List . iter loop args | Ucatch ( static_exn , vars , body , handler ) -> ignore_int static_exn ; ignore_params_with_value_kind vars ; loop body ; loop handler | Utrywith ( body , var , handler ) -> loop body ; ignore_var_with_provenance var ; loop handler | Uifthenelse ( cond , ifso , ifnot ) -> loop cond ; loop ifso ; loop ifnot | Usequence ( e1 , e2 ) -> loop e1 ; loop e2 | Uwhile ( cond , body ) -> loop cond ; loop body | Ufor ( var , low , high , direction_flag , body ) -> ignore_var_with_provenance var ; loop low ; loop high ; ignore_direction_flag direction_flag ; loop body | Uassign ( var , expr ) -> assigned_vars := V . Set . add var ! assigned_vars ; loop expr | Usend ( meth_kind , e1 , e2 , args , dbg ) -> ignore_meth_kind meth_kind ; loop e1 ; loop e2 ; List . iter loop args ; ignore_debuginfo dbg | Uunreachable -> ( ) in loop clam ; let linear = V . Tbl . fold ( fun var n acc -> assert ( n >= 1 ) ; if n = 1 && not ( V . Set . mem var ! assigned_vars ) then V . Set . add var acc else acc ) t V . Set . empty in let assigned = ! assigned_vars in let used = V . Tbl . fold ( fun var _n acc -> V . Set . add var acc ) t assigned in { used ; linear ; assigned ; closure_environment = ! environment_vars ; let_bound_vars_that_can_be_moved = V . Set . empty ; }
let let_bound_vars_that_can_be_moved var_info ( clam : Clambda . ulambda ) = let obviously_constant = ref V . Set . empty in let can_move = ref V . Set . empty in let let_stack = ref [ ] in let examine_argument_list args = let rec loop let_bound_vars ( args : Clambda . ulambda list ) = match let_bound_vars , args with | _ , [ ] -> let_bound_vars | [ ] , _ -> [ ] | let_bound_vars , ( Uvar arg ) :: args when V . Set . mem arg ! obviously_constant -> loop let_bound_vars args | let_bound_var :: let_bound_vars , ( Uvar arg ) :: args when V . same let_bound_var arg && not ( V . Set . mem arg var_info . assigned ) -> assert ( V . Set . mem arg var_info . used ) ; assert ( V . Set . mem arg var_info . linear ) ; can_move := V . Set . add arg ! can_move ; loop let_bound_vars args | _ :: _ , _ :: _ -> [ ] in let_stack := loop ! let_stack args in let rec loop : Clambda . ulambda -> unit = function | Uvar var -> if V . Set . mem var var_info . assigned then begin let_stack := [ ] end | Uconst const -> ignore_uconstant const | Udirect_apply ( label , args , dbg ) -> ignore_function_label label ; examine_argument_list args ; ignore_debuginfo dbg | Ugeneric_apply ( func , args , dbg ) -> examine_argument_list ( args @ [ func ] ) ; ignore_debuginfo dbg | Uclosure ( functions , captured_variables ) -> ignore_ulambda_list captured_variables ; List . iter ( fun { Clambda . label ; arity ; params ; return ; body ; dbg ; env } -> ignore_function_label label ; ignore_int arity ; ignore_params_with_value_kind params ; ignore_value_kind return ; let_stack := [ ] ; loop body ; let_stack := [ ] ; ignore_debuginfo dbg ; ignore_var_option env ) functions | Uoffset ( expr , offset ) -> examine_argument_list [ expr ] ; ignore_int offset | Ulet ( _let_kind , _value_kind , var , def , body ) -> let var = VP . var var in begin match def with | Uconst _ -> obviously_constant := V . Set . add var ! obviously_constant ; loop body | _ -> loop def ; if V . Set . mem var var_info . linear then begin let_stack := var ::! let_stack end else begin let_stack := [ ] end ; loop body end | Uphantom_let ( var , _defining_expr , body ) -> ignore_var_with_provenance var ; loop body | Uletrec ( defs , body ) -> let_stack := [ ] ; List . iter ( fun ( var , def ) -> ignore_var_with_provenance var ; loop def ; let_stack := [ ] ) defs ; loop body | Uprim ( prim , args , dbg ) -> ignore_primitive prim ; examine_argument_list args ; ignore_debuginfo dbg | Uswitch ( cond , { us_index_consts ; us_actions_consts ; us_index_blocks ; us_actions_blocks } , dbg ) -> examine_argument_list [ cond ] ; ignore_int_array us_index_consts ; Array . iter ( fun action -> let_stack := [ ] ; loop action ) us_actions_consts ; ignore_int_array us_index_blocks ; Array . iter ( fun action -> let_stack := [ ] ; loop action ) us_actions_blocks ; ignore_debuginfo dbg ; let_stack := [ ] | Ustringswitch ( cond , branches , default ) -> examine_argument_list [ cond ] ; List . iter ( fun ( str , branch ) -> ignore_string str ; let_stack := [ ] ; loop branch ) branches ; let_stack := [ ] ; Option . iter loop default ; let_stack := [ ] | Ustaticfail ( static_exn , args ) -> ignore_int static_exn ; examine_argument_list args | Ucatch ( static_exn , vars , body , handler ) -> ignore_int static_exn ; ignore_params_with_value_kind vars ; let_stack := [ ] ; loop body ; let_stack := [ ] ; loop handler ; let_stack := [ ] | Utrywith ( body , var , handler ) -> let_stack := [ ] ; loop body ; let_stack := [ ] ; ignore_var_with_provenance var ; loop handler ; let_stack := [ ] | Uifthenelse ( cond , ifso , ifnot ) -> examine_argument_list [ cond ] ; let_stack := [ ] ; loop ifso ; let_stack := [ ] ; loop ifnot ; let_stack := [ ] | Usequence ( e1 , e2 ) -> loop e1 ; let_stack := [ ] ; loop e2 ; let_stack := [ ] | Uwhile ( cond , body ) -> let_stack := [ ] ; loop cond ; let_stack := [ ] ; loop body ; let_stack := [ ] | Ufor ( var , low , high , direction_flag , body ) -> ignore_var_with_provenance var ; ignore_ulambda low ; ignore_ulambda high ; ignore_direction_flag direction_flag ; let_stack := [ ] ; loop body ; let_stack := [ ] | Uassign ( var , expr ) -> ignore_var var ; ignore_ulambda expr ; let_stack := [ ] | Usend ( meth_kind , e1 , e2 , args , dbg ) -> ignore_meth_kind meth_kind ; ignore_ulambda e1 ; ignore_ulambda e2 ; ignore_ulambda_list args ; let_stack := [ ] ; ignore_debuginfo dbg | Uunreachable -> let_stack := [ ] in loop clam ; ! can_move
let rec substitute_let_moveable is_let_moveable env ( clam : Clambda . ulambda ) : Clambda . ulambda = match clam with | Uvar var -> if not ( V . Set . mem var is_let_moveable ) then clam else begin match V . Map . find var env with | clam -> clam | exception Not_found -> Misc . fatal_errorf " substitute_let_moveable : Unbound variable % a " V . print var end | Uconst _ -> clam | Udirect_apply ( label , args , dbg ) -> let args = substitute_let_moveable_list is_let_moveable env args in Udirect_apply ( label , args , dbg ) | Ugeneric_apply ( func , args , dbg ) -> let func = substitute_let_moveable is_let_moveable env func in let args = substitute_let_moveable_list is_let_moveable env args in Ugeneric_apply ( func , args , dbg ) | Uclosure ( functions , variables_bound_by_the_closure ) -> let functions = List . map ( fun ( ufunction : Clambda . ufunction ) -> { ufunction with body = substitute_let_moveable is_let_moveable env ufunction . body ; } ) functions in let variables_bound_by_the_closure = substitute_let_moveable_list is_let_moveable env variables_bound_by_the_closure in Uclosure ( functions , variables_bound_by_the_closure ) | Uoffset ( clam , n ) -> let clam = substitute_let_moveable is_let_moveable env clam in Uoffset ( clam , n ) | Ulet ( let_kind , value_kind , var , def , body ) -> let def = substitute_let_moveable is_let_moveable env def in if V . Set . mem ( VP . var var ) is_let_moveable then let env = V . Map . add ( VP . var var ) def env in let body = substitute_let_moveable is_let_moveable env body in if not ! Clflags . debug_full then body else match def with | Uconst const -> Uphantom_let ( var , Some ( Clambda . Uphantom_const const ) , body ) | Uvar alias_of -> Uphantom_let ( var , Some ( Clambda . Uphantom_var alias_of ) , body ) | _ -> Uphantom_let ( var , None , body ) else Ulet ( let_kind , value_kind , var , def , substitute_let_moveable is_let_moveable env body ) | Uphantom_let ( var , defining_expr , body ) -> let body = substitute_let_moveable is_let_moveable env body in Uphantom_let ( var , defining_expr , body ) | Uletrec ( defs , body ) -> let defs = List . map ( fun ( var , def ) -> var , substitute_let_moveable is_let_moveable env def ) defs in let body = substitute_let_moveable is_let_moveable env body in Uletrec ( defs , body ) | Uprim ( prim , args , dbg ) -> let args = substitute_let_moveable_list is_let_moveable env args in Uprim ( prim , args , dbg ) | Uswitch ( cond , sw , dbg ) -> let cond = substitute_let_moveable is_let_moveable env cond in let sw = { sw with us_actions_consts = substitute_let_moveable_array is_let_moveable env sw . us_actions_consts ; us_actions_blocks = substitute_let_moveable_array is_let_moveable env sw . us_actions_blocks ; } in Uswitch ( cond , sw , dbg ) | Ustringswitch ( cond , branches , default ) -> let cond = substitute_let_moveable is_let_moveable env cond in let branches = List . map ( fun ( s , branch ) -> s , substitute_let_moveable is_let_moveable env branch ) branches in let default = Option . map ( substitute_let_moveable is_let_moveable env ) default in Ustringswitch ( cond , branches , default ) | Ustaticfail ( n , args ) -> let args = substitute_let_moveable_list is_let_moveable env args in Ustaticfail ( n , args ) | Ucatch ( n , vars , body , handler ) -> let body = substitute_let_moveable is_let_moveable env body in let handler = substitute_let_moveable is_let_moveable env handler in Ucatch ( n , vars , body , handler ) | Utrywith ( body , var , handler ) -> let body = substitute_let_moveable is_let_moveable env body in let handler = substitute_let_moveable is_let_moveable env handler in Utrywith ( body , var , handler ) | Uifthenelse ( cond , ifso , ifnot ) -> let cond = substitute_let_moveable is_let_moveable env cond in let ifso = substitute_let_moveable is_let_moveable env ifso in let ifnot = substitute_let_moveable is_let_moveable env ifnot in Uifthenelse ( cond , ifso , ifnot ) | Usequence ( e1 , e2 ) -> let e1 = substitute_let_moveable is_let_moveable env e1 in let e2 = substitute_let_moveable is_let_moveable env e2 in Usequence ( e1 , e2 ) | Uwhile ( cond , body ) -> let cond = substitute_let_moveable is_let_moveable env cond in let body = substitute_let_moveable is_let_moveable env body in Uwhile ( cond , body ) | Ufor ( var , low , high , direction , body ) -> let low = substitute_let_moveable is_let_moveable env low in let high = substitute_let_moveable is_let_moveable env high in let body = substitute_let_moveable is_let_moveable env body in Ufor ( var , low , high , direction , body ) | Uassign ( var , expr ) -> let expr = substitute_let_moveable is_let_moveable env expr in Uassign ( var , expr ) | Usend ( kind , e1 , e2 , args , dbg ) -> let e1 = substitute_let_moveable is_let_moveable env e1 in let e2 = substitute_let_moveable is_let_moveable env e2 in let args = substitute_let_moveable_list is_let_moveable env args in Usend ( kind , e1 , e2 , args , dbg ) | Uunreachable -> Uunreachable List . map ( substitute_let_moveable is_let_moveable env ) clams Array . map ( substitute_let_moveable is_let_moveable env ) clams
type moveable = Fixed | Constant | Moveable
let both_moveable a b = match a , b with | Constant , Constant -> Constant | Constant , Moveable | Moveable , Constant | Moveable , Moveable -> Moveable | Constant , Fixed | Moveable , Fixed | Fixed , Constant | Fixed , Moveable | Fixed , Fixed -> Fixed
let primitive_moveable ( prim : Clambda_primitives . primitive ) ( args : Clambda . ulambda list ) ( var_info : var_info ) = match prim , args with | Pfield _ , [ Uconst ( Uconst_ref ( _ , _ ) ) ] -> Moveable | Pfield _ , [ Uvar var ] when V . Set . mem var var_info . closure_environment -> Moveable | _ -> match Semantics_of_primitives . for_primitive prim with | No_effects , No_coeffects -> Moveable | No_effects , Has_coeffects | Only_generative_effects , No_coeffects | Only_generative_effects , Has_coeffects | Arbitrary_effects , No_coeffects | Arbitrary_effects , Has_coeffects -> Fixed
type moveable_for_env = Constant | Moveable
let rec un_anf_and_moveable var_info env ( clam : Clambda . ulambda ) : Clambda . ulambda * moveable = match clam with | Uvar var -> begin match V . Map . find var env with | Constant , def -> def , Constant | Moveable , def -> def , Moveable | exception Not_found -> let moveable : moveable = if V . Set . mem var var_info . assigned then Fixed else Moveable in clam , moveable end | Uconst _ -> clam , Constant | Udirect_apply ( label , args , dbg ) -> let args = un_anf_list var_info env args in Udirect_apply ( label , args , dbg ) , Fixed | Ugeneric_apply ( func , args , dbg ) -> let func = un_anf var_info env func in let args = un_anf_list var_info env args in Ugeneric_apply ( func , args , dbg ) , Fixed | Uclosure ( functions , variables_bound_by_the_closure ) -> let functions = List . map ( fun ( ufunction : Clambda . ufunction ) -> { ufunction with body = un_anf var_info env ufunction . body ; } ) functions in let variables_bound_by_the_closure = un_anf_list var_info env variables_bound_by_the_closure in Uclosure ( functions , variables_bound_by_the_closure ) , Fixed | Uoffset ( clam , n ) -> let clam , moveable = un_anf_and_moveable var_info env clam in Uoffset ( clam , n ) , both_moveable Moveable moveable | Ulet ( _let_kind , _value_kind , var , def , Uvar var ' ) when V . same ( VP . var var ) var ' -> un_anf_and_moveable var_info env def | Ulet ( let_kind , value_kind , var , def , body ) -> let def , def_moveable = un_anf_and_moveable var_info env def in let is_linear = V . Set . mem ( VP . var var ) var_info . linear in let is_used = V . Set . mem ( VP . var var ) var_info . used in let is_assigned = V . Set . mem ( VP . var var ) var_info . assigned in let maybe_for_debugger ( body , moveable ) : Clambda . ulambda * moveable = if not ! Clflags . debug_full then body , moveable else match def with | Uconst const -> Uphantom_let ( var , Some ( Clambda . Uphantom_const const ) , body ) , moveable | Uvar alias_of -> Uphantom_let ( var , Some ( Clambda . Uphantom_var alias_of ) , body ) , moveable | _ -> Uphantom_let ( var , None , body ) , moveable in begin match def_moveable , is_linear , is_used , is_assigned with | ( Constant | Moveable ) , _ , false , _ -> maybe_for_debugger ( un_anf_and_moveable var_info env body ) | Constant , _ , true , false | Moveable , true , true , false -> let def_moveable = match def_moveable with | Moveable -> Moveable | Constant -> Constant | Fixed -> assert false in let env = V . Map . add ( VP . var var ) ( def_moveable , def ) env in maybe_for_debugger ( un_anf_and_moveable var_info env body ) | ( Constant | Moveable ) , _ , _ , true | Moveable , false , _ , _ | Fixed , _ , _ , _ -> let body , body_moveable = un_anf_and_moveable var_info env body in Ulet ( let_kind , value_kind , var , def , body ) , both_moveable def_moveable body_moveable end | Uphantom_let ( var , defining_expr , body ) -> let body , body_moveable = un_anf_and_moveable var_info env body in Uphantom_let ( var , defining_expr , body ) , body_moveable | Uletrec ( defs , body ) -> let defs = List . map ( fun ( var , def ) -> var , un_anf var_info env def ) defs in let body = un_anf var_info env body in Uletrec ( defs , body ) , Fixed | Uprim ( prim , args , dbg ) -> let args , args_moveable = un_anf_list_and_moveable var_info env args in let moveable = both_moveable args_moveable ( primitive_moveable prim args var_info ) in Uprim ( prim , args , dbg ) , moveable | Uswitch ( cond , sw , dbg ) -> let cond = un_anf var_info env cond in let sw = { sw with us_actions_consts = un_anf_array var_info env sw . us_actions_consts ; us_actions_blocks = un_anf_array var_info env sw . us_actions_blocks ; } in Uswitch ( cond , sw , dbg ) , Fixed | Ustringswitch ( cond , branches , default ) -> let cond = un_anf var_info env cond in let branches = List . map ( fun ( s , branch ) -> s , un_anf var_info env branch ) branches in let default = Option . map ( un_anf var_info env ) default in Ustringswitch ( cond , branches , default ) , Fixed | Ustaticfail ( n , args ) -> let args = un_anf_list var_info env args in Ustaticfail ( n , args ) , Fixed | Ucatch ( n , vars , body , handler ) -> let body = un_anf var_info env body in let handler = un_anf var_info env handler in Ucatch ( n , vars , body , handler ) , Fixed | Utrywith ( body , var , handler ) -> let body = un_anf var_info env body in let handler = un_anf var_info env handler in Utrywith ( body , var , handler ) , Fixed | Uifthenelse ( cond , ifso , ifnot ) -> let cond , cond_moveable = un_anf_and_moveable var_info env cond in let ifso , ifso_moveable = un_anf_and_moveable var_info env ifso in let ifnot , ifnot_moveable = un_anf_and_moveable var_info env ifnot in let moveable = both_moveable cond_moveable ( both_moveable ifso_moveable ifnot_moveable ) in Uifthenelse ( cond , ifso , ifnot ) , moveable | Usequence ( e1 , e2 ) -> let e1 = un_anf var_info env e1 in let e2 = un_anf var_info env e2 in Usequence ( e1 , e2 ) , Fixed | Uwhile ( cond , body ) -> let cond = un_anf var_info env cond in let body = un_anf var_info env body in Uwhile ( cond , body ) , Fixed | Ufor ( var , low , high , direction , body ) -> let low = un_anf var_info env low in let high = un_anf var_info env high in let body = un_anf var_info env body in Ufor ( var , low , high , direction , body ) , Fixed | Uassign ( var , expr ) -> let expr = un_anf var_info env expr in Uassign ( var , expr ) , Fixed | Usend ( kind , e1 , e2 , args , dbg ) -> let e1 = un_anf var_info env e1 in let e2 = un_anf var_info env e2 in let args = un_anf_list var_info env args in Usend ( kind , e1 , e2 , args , dbg ) , Fixed | Uunreachable -> Uunreachable , Fixed let clam , _moveable = un_anf_and_moveable var_info env clam in clam : Clambda . ulambda list * moveable = List . fold_right ( fun clam ( l , acc_moveable ) -> let clam , moveable = un_anf_and_moveable var_info env clam in clam :: l , both_moveable moveable acc_moveable ) clams ( [ ] , ( Moveable : moveable ) ) let clams , _moveable = un_anf_list_and_moveable var_info env clams in clams Array . map ( un_anf var_info env ) clams
let apply ~ what ~ ppf_dump clam = let var_info = make_var_info clam in let let_bound_vars_that_can_be_moved = let_bound_vars_that_can_be_moved var_info clam in let clam = substitute_let_moveable let_bound_vars_that_can_be_moved V . Map . empty clam in let var_info = make_var_info clam in let clam = un_anf var_info V . Map . empty clam in if ! Clflags . dump_clambda then begin Format . fprintf ppf_dump " . @ un - anf ( % a ) :@ % a . " @ Symbol . print what Printclambda . clambda clam end ; clam
type ' a t = ' a
let none = " Uopt . none " |> ( Obj . magic : string -> _ t )
let is_none t = phys_equal t none
let is_some t = not ( is_none t )
let invariant invariant_a t = if is_some t then invariant_a t
let sexp_of_t sexp_of_a t = if is_none t then [ % sexp None ] else [ % sexp Some ( t : a ) ]
let some a = a
let value_exn t = if is_none t then failwith " Uopt . value_exn " else t
let unsafe_value t = t
let to_option t = if is_none t then None else Some t
let of_option = function | None -> none | Some a -> some a ; ;
module Optional_syntax = struct module Optional_syntax = struct let is_none = is_none let unsafe_value = unsafe_value end end
let usage ( ) = prerr_endline { | Usage : PIPELINE =< PIPELINE_ID > dune exec tezt / records / update . exe exit 1
let pipeline = match Sys . getenv_opt " PIPELINE " with | None -> usage ( ) | Some value -> ( match int_of_string_opt value with | None -> prerr_endline " Invalid pipeline ID ( not an integer ) . \ n " ; usage ( ) | Some value -> value )
let project = Sys . getenv_opt " PROJECT " |> Option . value ~ default " : tezos / tezos "
let rec get_all_pages ( ? from = 1 ) ( ? acc = [ ] ) url = let full_url = url ^ " ? page " = ^ string_of_int from in let * response_body = Process . run_and_read_stdout " curl " [ full_url ] in let list = JSON . parse ~ origin : url response_body |> JSON . as_list in Log . info " Found % d jobs in page % d . " ( List . length list ) from ; match list with | [ ] -> return ( List . rev acc ) | _ :: _ -> get_all_pages ~ from ( : from + 1 ) ~ acc ( : List . rev_append list acc ) url
let fetch_record ( url , index ) = let local = records_directory // ( index ^ " . json " ) in let * ( ) = Process . run " curl " [ url ; " -- location " ; " -- output " ; local ] in Log . info " Downloaded : % s " local ; match JSON . parse_file local with | exception ( JSON . Error _ as exn ) -> Log . error " Failed to parse downloaded JSON file , maybe the artifact has expired " ? ; raise exn | ( _ : JSON . t ) -> unit
let remove_existing_records ( ) = let remove_if_looks_like_a_record filename = if filename =~ rex " ^\\ d . +\\ json " $ then ( let filename = records_directory // filename in Sys . remove filename ; Log . info " Removed outdated record : % s " filename ) in Array . iter remove_if_looks_like_a_record ( Sys . readdir records_directory )
let fetch_pipeline_records ( ) = let * jobs = get_all_pages ( " https :// gitlab . com / api / v4 / projects " / ^ Uri . pct_encode project ^ " / pipelines " / ^ string_of_int pipeline ^ " / jobs " ) in let get_record job = let job_id = JSON . ( job |-> " id " |> as_int ) in let name = JSON . ( job |-> " name " |> as_string ) in match name =~* rex " ^ tezt ( \\ d ) +/\\ d " +$ with | None -> None | Some index -> Some ( " https :// gitlab . com " / ^ project ^ " /-/ jobs " / ^ string_of_int job_id ^ " / artifacts / file / tezt - results " - ^ index ^ " . json " , index ) in let records = List . filter_map get_record jobs in Log . info " Found % d Tezt jobs . " ( List . length records ) ; Lwt_list . iter_p fetch_record records
let ( ) = Cli . init ( ) ; ( Test . register ~ __FILE__ ~ title " : update records " ~ tags [ " : update " ] @@ fun ( ) -> remove_existing_records ( ) ; fetch_pipeline_records ( ) ) ; Test . run ( )
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 - 06 " ] ) ; ( " Action " , [ " UpdateAssociationStatus " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateAssociationStatusRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateAssociationStatusResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateAssociationStatusResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateAssociationStatusResult . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateAssociationStatusResult - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
let parse_error code err = let errors = [ Errors_internal . TooManyUpdates ; Errors_internal . StatusUnchanged ; Errors_internal . AssociationDoesNotExist ; Errors_internal . InvalidDocument ; Errors_internal . InvalidInstanceId ; Errors_internal . InternalServerError ] @ 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 location_map = ref ( NodeMap . create 103 : location NodeMap . t )
let getLoc ( node : Node . t ) = try NodeMap . find ! location_map node with Not_found -> Node . location node
let store_node_location ( n : Node . t ) ( l : location ) : unit = NodeMap . add ! location_map n l
let update_ids ( old_file : file ) ( ids : max_ids ) ( new_file : file ) ( changes : change_info ) = let vid_max = ref ids . max_vid in let sid_max = ref ids . max_sid in let update_vid_max vid = update_id_max vid_max vid in let update_sid_max sid = update_id_max sid_max sid in let make_vid ( ) = incr vid_max ; ! vid_max in let make_sid ( ) = incr sid_max ; ! sid_max in let override_fundec ( target : fundec ) ( src : fundec ) = target . sbody <- src . sbody ; target . sallstmts <- src . sallstmts ; target . sformals <- src . sformals ; target . slocals <- src . slocals ; target . smaxid <- src . smaxid ; target . smaxstmtid <- src . smaxstmtid ; target . svar <- src . svar ; in let reset_fun ( f : fundec ) ( old_f : fundec ) = f . svar . vid <- old_f . svar . vid ; List . iter2 ( fun l o_l -> l . vid <- o_l . vid ) f . slocals old_f . slocals ; List . iter2 ( fun lo o_f -> lo . vid <- o_f . vid ) f . sformals old_f . sformals ; List . iter2 ( fun s o_s -> s . sid <- o_s . sid ) f . sallstmts old_f . sallstmts ; List . iter ( fun s -> store_node_location ( Statement s ) ( Cilfacade . get_stmtLoc s ) ) f . sallstmts ; store_node_location ( Function f ) f . svar . vdecl ; store_node_location ( FunctionEntry f ) f . svar . vdecl ; override_fundec f old_f ; List . iter ( fun l -> update_vid_max l . vid ) f . slocals ; List . iter ( fun f -> update_vid_max f . vid ) f . sformals ; List . iter ( fun s -> update_sid_max s . sid ) f . sallstmts ; update_vid_max f . svar . vid ; in let reset_var ( v : varinfo ) ( old_v : varinfo ) = v . vid <- old_v . vid ; update_vid_max v . vid ; in let reset_globals ( glob : unchanged_global ) = try match glob . current , glob . old with | GFun ( nw , _ ) , GFun ( old , _ ) -> reset_fun nw old | GVar ( nw , _ , _ ) , GVar ( old , _ , _ ) -> reset_var nw old | GVarDecl ( nw , _ ) , GVarDecl ( old , _ ) -> reset_var nw old | _ -> ( ) with Failure m -> ( ) in let assign_same_id fallstmts ( old_n , n ) = match old_n , n with | Statement old_s , Statement s -> if List . exists ( fun s ' -> Node . equal n ( Statement s ' ) ) fallstmts then ( s . sid <- old_s . sid ; update_sid_max s . sid ) | FunctionEntry old_f , FunctionEntry f -> f . svar . vid <- old_f . svar . vid ; update_vid_max f . svar . vid | Function old_f , Function f -> f . svar . vid <- old_f . svar . vid ; update_vid_max f . svar . vid | _ -> raise ( Failure " Node tuple falsely classified as unchanged nodes " ) in let reset_changed_stmt ( unchangedNodes : node list ) s = if not ( List . exists ( fun n -> Node . equal n ( Statement s ) ) unchangedNodes ) then s . sid <- make_sid ( ) in let reset_changed_fun ( f : fundec ) ( old_f : fundec ) unchangedHeader ( diff : nodes_diff option ) = f . svar . vid <- old_f . svar . vid ; update_vid_max f . svar . vid ; if unchangedHeader then List . iter2 ( fun f old_f -> f . vid <- old_f . vid ; update_vid_max f . vid ) f . sformals old_f . sformals else List . iter ( fun f -> f . vid <- make_vid ( ) ) f . sformals ; match diff with | None -> List . iter ( fun l -> l . vid <- make_vid ( ) ) f . slocals ; List . iter ( fun s -> s . sid <- make_sid ( ) ) f . sallstmts ; | Some d -> List . iter2 ( fun l o_l -> l . vid <- o_l . vid ) f . slocals old_f . slocals ; List . iter ( fun l -> update_vid_max l . vid ) f . slocals ; List . iter ( reset_changed_stmt ( List . map snd d . unchangedNodes ) ) f . sallstmts ; List . iter ( assign_same_id f . sallstmts ) d . unchangedNodes in let reset_changed_globals ( changed : changed_global ) = match ( changed . current , changed . old ) with | GFun ( nw , _ ) , GFun ( old , _ ) -> reset_changed_fun nw old changed . unchangedHeader changed . diff | _ -> ( ) in let update_fun ( f : fundec ) = f . svar . vid <- make_vid ( ) ; List . iter ( fun l -> l . vid <- make_vid ( ) ) f . slocals ; List . iter ( fun f -> f . vid <- make_vid ( ) ) f . sformals ; List . iter ( fun s -> s . sid <- make_sid ( ) ) f . sallstmts ; in let update_var ( v : varinfo ) = v . vid <- make_vid ( ) in let update_globals ( glob : global ) = try match glob with | GFun ( nw , _ ) -> update_fun nw | GVar ( nw , _ , _ ) -> update_var nw | GVarDecl ( nw , _ ) -> update_var nw | _ -> ( ) with Failure m -> ( ) in List . iter reset_globals changes . unchanged ; List . iter reset_changed_globals changes . changed ; List . iter update_globals changes . added ; Cil . iterGlobals new_file ( update_max_ids ~ sid_max ~ vid_max ) ; while ! sid_max > Cil . new_sid ( ) do ( ) done ; { max_sid = ! sid_max ; max_vid = ! vid_max }
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 " , [ " 2013 - 04 - 01 " ] ) ; ( " Action " , [ " UpdateHealthCheck " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateHealthCheckRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateHealthCheckResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateHealthCheckResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateHealthCheckResponse . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateHealthCheckResponse - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2013 - 04 - 01 " ] ) ; ( " Action " , [ " UpdateHostedZoneComment " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateHostedZoneCommentRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateHostedZoneCommentResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateHostedZoneCommentResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateHostedZoneCommentResponse . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateHostedZoneCommentResponse - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 datadir = ref None
let get_datadir ( ) = match ! datadir with | None -> Events . ( emit node_uninitialized ) ( ) >>= fun ( ) -> Lwt_exit . exit_and_raise 1 | Some m -> Lwt . return m
let init dir = datadir := Some dir
let then_false ( ) = Lwt . return_false
let do_compile hash p = get_datadir ( ) >>= fun datadir -> let source_dir = datadir // Protocol_hash . to_short_b58check hash // " src " in let log_file = datadir // Protocol_hash . to_short_b58check hash // " LOG " in let plugin_file = datadir // Protocol_hash . to_short_b58check hash // Format . asprintf " protocol_ % a " Protocol_hash . pp hash in ( Tezos_base_unix . Protocol_files . write_dir source_dir ~ hash p >>=? fun ( ) -> let compiler_command = ( Sys . executable_name , Array . of_list [ compiler_name ; " - register " ; " - o " ; plugin_file ; source_dir ] ) in let fd = Unix . ( openfile log_file [ O_WRONLY ; O_CREAT ; O_TRUNC ] 0o644 ) in Lwt_process . exec ~ stdin ` : Close ~ stdout ( ` : FD_copy fd ) ~ stderr ( ` : FD_move fd ) compiler_command >>= return ) >>= function | Error err -> Events . ( emit compiler_exit_error ) err >>= then_false | Ok ( Unix . WSIGNALED _ | Unix . WSTOPPED _ ) -> Events . ( emit compilation_interrupted ) log_file >>= then_false | Ok ( Unix . WEXITED x ) when x <> 0 -> Events . ( emit compilation_error ) log_file >>= then_false | Ok ( Unix . WEXITED _ ) -> ( try Dynlink . loadfile_private ( plugin_file ^ " . cmxs " ) ; Lwt . return_true with | Dynlink . ( Error ( Cannot_open_dynamic_library exn ) ) -> Events . ( emit dynlink_error_static ) ( plugin_file , Printexc . to_string exn ) >>= then_false | Dynlink . ( Error err ) -> Events . ( emit dynlink_error ) ( plugin_file , Dynlink . error_message err ) >>= then_false )
let compile hash p = if Tezos_protocol_registerer . Registerer . mem hash then Lwt . return_true else do_compile hash p >>= fun success -> let loaded = Tezos_protocol_registerer . Registerer . mem hash in if success && not loaded then Events . ( emit internal_error ) hash >>= fun ( ) -> Lwt . return loaded else Lwt . return loaded
let node_uninitialized = declare_0 ~ section ~ level ~ name " : node_uninitialized " ~ msg " : node not initialized " ( )
let compiler_exit_error = declare_1 ~ section ~ level ~ name " : compiler_exit_error " ~ msg " : error : { error } " ( " error " , Error_monad . ( TzTrace . encoding error_encoding ) )
let compilation_interrupted = declare_1 ~ section ~ level ~ name " : compilation_interrupted " ~ msg " : compilation interrupted ( see logs in : { filename } ) " ( " filename " , Data_encoding . string )
let compilation_error = declare_1 ~ section ~ level ~ name " : compilation_error " ~ msg " : compilation error ( logs in file : { filename } ) " ( " filename " , Data_encoding . string )
let dynlink_error = declare_2 ~ section ~ level ~ name " : dynlink_error " ~ msg " : can ' t load plugin : { plugin } ( { reason } ) " ( " plugin " , Data_encoding . string ) ( " reason " , Data_encoding . string )
let dynlink_error_static = declare_2 ~ section ~ level ~ name " : dynlink_error_static " ~ msg : " can ' t load plugin either because the binary is statically linked or \ because there was an error in its compilation : { plugin } ( { reason } ) " ( " plugin " , Data_encoding . string ) ( " reason " , Data_encoding . string )
let internal_error = declare_1 ~ section ~ level ~ name " : internal_error " ~ msg " : internal error while compiling { protocol } " ( " protocol " , Protocol_hash . encoding )
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 " , [ " UpdateSecurityGroupRuleDescriptionsEgress " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateSecurityGroupRuleDescriptionsEgressRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateSecurityGroupRuleDescriptionsEgressResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateSecurityGroupRuleDescriptionsEgressResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateSecurityGroupRuleDescriptionsEgressResult . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateSecurityGroupRuleDescriptionsEgressResult - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " UpdateSecurityGroupRuleDescriptionsIngress " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateSecurityGroupRuleDescriptionsIngressRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateSecurityGroupRuleDescriptionsIngressResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateSecurityGroupRuleDescriptionsIngressResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateSecurityGroupRuleDescriptionsIngressResult . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateSecurityGroupRuleDescriptionsIngressResult - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2010 - 05 - 15 " ] ) ; ( " Action " , [ " UpdateStack " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateStackInput . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " UpdateStackResponse " ( snd xml ) ) ( Xml . member " UpdateStackResult " ) in try Util . or_error ( Util . option_bind resp UpdateStackOutput . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateStackOutput . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateStackOutput - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2010 - 05 - 15 " ] ) ; ( " Action " , [ " UpdateStackInstances " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateStackInstancesInput . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " UpdateStackInstancesResponse " ( snd xml ) ) ( Xml . member " UpdateStackInstancesResult " ) in try Util . or_error ( Util . option_bind resp UpdateStackInstancesOutput . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateStackInstancesOutput . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateStackInstancesOutput - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2010 - 05 - 15 " ] ) ; ( " Action " , [ " UpdateStackSet " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateStackSetInput . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " UpdateStackSetResponse " ( snd xml ) ) ( Xml . member " UpdateStackSetResult " ) in try Util . or_error ( Util . option_bind resp UpdateStackSetOutput . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateStackSetOutput . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateStackSetOutput - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2010 - 05 - 15 " ] ) ; ( " Action " , [ " UpdateTerminationProtection " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateTerminationProtectionInput . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " UpdateTerminationProtectionResponse " ( snd xml ) ) ( Xml . member " UpdateTerminationProtectionResult " ) in try Util . or_error ( Util . option_bind resp UpdateTerminationProtectionOutput . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateTerminationProtectionOutput . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateTerminationProtectionOutput - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2013 - 04 - 01 " ] ) ; ( " Action " , [ " UpdateTrafficPolicyComment " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateTrafficPolicyCommentRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateTrafficPolicyCommentResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateTrafficPolicyCommentResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateTrafficPolicyCommentResponse . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateTrafficPolicyCommentResponse - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2013 - 04 - 01 " ] ) ; ( " Action " , [ " UpdateTrafficPolicyInstance " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateTrafficPolicyInstanceRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateTrafficPolicyInstanceResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateTrafficPolicyInstanceResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateTrafficPolicyInstanceResponse . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateTrafficPolicyInstanceResponse - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
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 " , [ " 2013 - 11 - 01 " ] ) ; ( " Action " , [ " UpdateTrail " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( UpdateTrailRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UpdateTrailResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UpdateTrailResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UpdateTrailResponse . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing UpdateTrailResponse - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )