text
stringlengths 0
601k
|
---|
type huffman = | Found of int | NeedBit of huffman * huffman | NeedBits of int * huffman array |
type adler32 = { mutable a1 : int ; mutable a2 : int ; } |
type window = { mutable wbuffer : Bytes . t ; mutable wpos : int ; wcrc : adler32 ; } |
type state = | Head | Block | CData | Flat | Crc | Dist | DistOne | Done |
type t = { mutable znbits : int ; mutable zbits : int ; mutable zstate : state ; mutable zfinal : bool ; mutable zhuffman : huffman ; mutable zhuffdist : huffman option ; mutable zlen : int ; mutable zdist : int ; mutable zneeded : int ; mutable zoutput : Bytes . t ; mutable zoutpos : int ; zinput : IO . input ; zlengths : int array ; zwindow : window ; } |
type error_msg = | Invalid_huffman | Invalid_data | Invalid_crc | Truncated_data | Unsupported_dictionary |
let error msg = raise ( Error msg ) msg |
let rec tree_depth = function | Found _ -> 0 | NeedBits _ -> assert false | NeedBit ( a , b ) b -> 1 + min ( tree_depth a ) a ( tree_depth b ) b |
let rec tree_compress t = match tree_depth t with | 0 -> t | 1 -> ( match t with | NeedBit ( a , b ) b -> NeedBit ( tree_compress a , tree_compress b ) b | _ -> assert false ) false | d -> let size = 1 lsl d in let tbl = Array . make size ( Found ( - 1 ) 1 ) 1 in tree_walk tbl 0 0 d t ; NeedBits ( d , tbl ) tbl | NeedBit ( a , b ) b when d > 0 -> tree_walk tbl p ( cd + 1 ) 1 ( d - 1 ) 1 a ; tree_walk tbl ( p lor ( 1 lsl cd ) cd ) cd ( cd + 1 ) 1 ( d - 1 ) 1 b ; | t -> Array . set tbl p ( tree_compress t ) t |
let make_huffman lengths pos nlengths maxbits = let counts = Array . make maxbits 0 in for i = 0 to nlengths - 1 do let p = Array . unsafe_get lengths ( i + pos ) pos in if p >= maxbits then error Invalid_huffman ; Array . unsafe_set counts p ( Array . unsafe_get counts p + 1 ) 1 ; done ; let code = ref 0 in let tmp = Array . make maxbits 0 in for i = 1 to maxbits - 2 do code := ( ! code + Array . unsafe_get counts i ) i lsl 1 ; Array . unsafe_set tmp i ! code ; done ; let bits = Hashtbl . create 0 in for i = 0 to nlengths - 1 do let l = Array . unsafe_get lengths ( i + pos ) pos in if l <> 0 then begin let n = Array . unsafe_get tmp ( l - 1 ) 1 in Array . unsafe_set tmp ( l - 1 ) 1 ( n + 1 ) 1 ; Hashtbl . add bits ( n , l ) l i ; end ; done ; let rec tree_make v l = if l > maxbits then error Invalid_huffman ; try Found ( Hashtbl . find bits ( v , l ) l ) l with Not_found -> NeedBit ( tree_make ( v lsl 1 ) 1 ( l + 1 ) 1 , tree_make ( v lsl 1 lor 1 ) 1 ( l + 1 ) 1 ) 1 in tree_compress ( NeedBit ( tree_make 0 1 , tree_make 1 1 ) 1 ) 1 |
let adler32_create ( adler32_create ) adler32_create = { a1 = 1 ; a2 = 0 ; } |
let adler32_update a s p l = let p = ref p in for i = 0 to l - 1 do let c = int_of_char ( Bytes . unsafe_get s ! p ) p in a . a1 <- ( a . a1 + c ) c mod 65521 ; a . a2 <- ( a . a2 + a . a1 ) a1 mod 65521 ; incr p ; done |
let adler32_read ch = let a2a = IO . read_byte ch in let a2b = IO . read_byte ch in let a1a = IO . read_byte ch in let a1b = IO . read_byte ch in { a1 = ( a1a lsl 8 ) 8 lor a1b ; a2 = ( a2a lsl 8 ) 8 lor a2b ; } |
let window_size = 1 lsl 15 |
let buffer_size = 1 lsl 16 |
let window_create size = { wbuffer = Bytes . create buffer_size ; wpos = 0 ; wcrc = adler32_create ( adler32_create ) adler32_create } |
let window_slide w = adler32_update w . wcrc w . wbuffer 0 window_size ; let b = Bytes . create buffer_size in w . wpos <- w . wpos - window_size ; Bytes . unsafe_blit w . wbuffer window_size b 0 w . wpos ; w . wbuffer <- b |
let window_add_bytes w s p len = if w . wpos + len > buffer_size then window_slide w ; Bytes . unsafe_blit s p w . wbuffer w . wpos len ; w . wpos <- w . wpos + len |
let window_add_char w c = if w . wpos = buffer_size then window_slide w ; Bytes . unsafe_set w . wbuffer w . wpos c ; w . wpos <- w . wpos + 1 |
let window_get_last_char w = Bytes . unsafe_get w . wbuffer ( w . wpos - 1 ) 1 |
let window_available w = w . wpos |
let window_checksum w = adler32_update w . wcrc w . wbuffer 0 w . wpos ; w . wcrc |
let fixed_huffman = make_huffman ( Array . init 288 ( fun n -> if n <= 143 then 8 else if n <= 255 then 9 else if n <= 279 then 7 else 8 ) ) 0 288 10 |
let get_bits z n = while z . znbits < n do z . zbits <- z . zbits lor ( ( IO . read_byte z . zinput ) zinput lsl z . znbits ) znbits ; z . znbits <- z . znbits + 8 ; done ; let b = z . zbits land ( 1 lsl n - 1 ) 1 in z . znbits <- z . znbits - n ; z . zbits <- z . zbits lsr n ; b |
let get_bit z = if z . znbits = 0 then begin z . znbits <- 8 ; z . zbits <- IO . read_byte z . zinput ; end ; let b = z . zbits land 1 = 1 in z . znbits <- z . znbits - 1 ; z . zbits <- z . zbits lsr 1 ; b |
let rec get_rev_bits z n = if n = 0 then 0 else if get_bit z then ( 1 lsl ( n - 1 ) 1 ) 1 lor ( get_rev_bits z ( n - 1 ) 1 ) 1 else get_rev_bits z ( n - 1 ) 1 |
let reset_bits z = z . zbits <- 0 ; z . znbits <- 0 |
let add_bytes z s p l = window_add_bytes z . zwindow s p l ; Bytes . unsafe_blit s p z . zoutput z . zoutpos l ; z . zneeded <- z . zneeded - l ; z . zoutpos <- z . zoutpos + l |
let add_char z c = window_add_char z . zwindow c ; Bytes . unsafe_set z . zoutput z . zoutpos c ; z . zneeded <- z . zneeded - 1 ; z . zoutpos <- z . zoutpos + 1 |
let add_dist_one z n = let c = window_get_last_char z . zwindow in let s = Bytes . make n c in add_bytes z s 0 n |
let add_dist z d l = add_bytes z z . zwindow . wbuffer ( z . zwindow . wpos - d ) d l |
let rec apply_huffman z = function | Found n -> n | NeedBit ( a , b ) b -> apply_huffman z ( if get_bit z then b else a ) a | NeedBits ( n , t ) t -> apply_huffman z ( Array . unsafe_get t ( get_bits z n ) n ) n |
let inflate_lengths z a max = let i = ref 0 in let prev = ref 0 in while ! i < max do match apply_huffman z z . zhuffman with | n when n <= 15 -> prev := n ; Array . unsafe_set a ! i n ; incr i | 16 -> let n = 3 + get_bits z 2 in if ! i + n > max then error Invalid_data ; for k = 0 to n - 1 do Array . unsafe_set a ! i ! prev ; incr i ; done ; | 17 -> let n = 3 + get_bits z 3 in i := ! i + n ; if ! i > max then error Invalid_data ; | 18 -> let n = 11 + get_bits z 7 in i := ! i + n ; if ! i > max then error Invalid_data ; | _ -> error Invalid_data done |
let rec inflate_loop z = match z . zstate with | Head -> let cmf = IO . read_byte z . zinput in let cm = cmf land 15 in let cinfo = cmf lsr 4 in if cm <> 8 || cinfo <> 7 then error Invalid_data ; let flg = IO . read_byte z . zinput in let fdict = flg land 32 <> 0 in if ( cmf lsl 8 + flg ) flg mod 31 <> 0 then error Invalid_data ; if fdict then error Unsupported_dictionary ; z . zstate <- Block ; inflate_loop z | Crc -> let calc = window_checksum z . zwindow in let crc = adler32_read z . zinput in if calc <> crc then error Invalid_crc ; z . zstate <- Done ; inflate_loop z | Done -> ( ) | Block -> z . zfinal <- get_bit z ; let btype = get_bits z 2 in ( match btype with | 0 -> z . zlen <- IO . read_ui16 z . zinput ; let nlen = IO . read_ui16 z . zinput in if nlen <> 0xffff - z . zlen then error Invalid_data ; z . zstate <- Flat ; inflate_loop z ; reset_bits z | 1 -> z . zhuffman <- fixed_huffman ; z . zhuffdist <- None ; z . zstate <- CData ; inflate_loop z | 2 -> let hlit = get_bits z 5 + 257 in let hdist = get_bits z 5 + 1 in let hclen = get_bits z 4 + 4 in for i = 0 to hclen - 1 do Array . unsafe_set z . zlengths ( Array . unsafe_get code_lengths_pos i ) i ( get_bits z 3 ) 3 ; done ; for i = hclen to 18 do Array . unsafe_set z . zlengths ( Array . unsafe_get code_lengths_pos i ) i 0 ; done ; z . zhuffman <- make_huffman z . zlengths 0 19 8 ; let lengths = Array . make ( hlit + hdist ) hdist 0 in inflate_lengths z lengths ( hlit + hdist ) hdist ; z . zhuffdist <- Some ( make_huffman lengths hlit hdist 16 ) 16 ; z . zhuffman <- make_huffman lengths 0 hlit 16 ; z . zstate <- CData ; inflate_loop z | _ -> error Invalid_data ) Invalid_data | Flat -> let rlen = min z . zlen z . zneeded in let str = IO . nread z . zinput rlen in let len = Bytes . length str in z . zlen <- z . zlen - len ; add_bytes z str 0 len ; if z . zlen = 0 then z . zstate <- ( if z . zfinal then Crc else Block ) Block ; if z . zneeded > 0 then inflate_loop z | DistOne -> let len = min z . zlen z . zneeded in add_dist_one z len ; z . zlen <- z . zlen - len ; if z . zlen = 0 then z . zstate <- CData ; if z . zneeded > 0 then inflate_loop z | Dist -> while z . zlen > 0 && z . zneeded > 0 do let len = min z . zneeded ( min z . zlen z . zdist ) zdist in add_dist z z . zdist len ; z . zlen <- z . zlen - len ; done ; if z . zlen = 0 then z . zstate <- CData ; if z . zneeded > 0 then inflate_loop z | CData -> match apply_huffman z z . zhuffman with | n when n < 256 -> add_char z ( Char . unsafe_chr n ) n ; if z . zneeded > 0 then inflate_loop z | 256 -> z . zstate <- if z . zfinal then Crc else Block ; inflate_loop z | n -> let n = n - 257 in let extra_bits = Array . unsafe_get len_extra_bits_tbl n in if extra_bits = - 1 then error Invalid_data ; z . zlen <- ( Array . unsafe_get len_base_val_tbl n ) n + ( get_bits z extra_bits ) extra_bits ; let dist_code = ( match z . zhuffdist with None -> get_rev_bits z 5 | Some h -> apply_huffman z h ) h in let extra_bits = Array . unsafe_get dist_extra_bits_tbl dist_code in if extra_bits = - 1 then error Invalid_data ; z . zdist <- ( Array . unsafe_get dist_base_val_tbl dist_code ) dist_code + ( get_bits z extra_bits ) extra_bits ; if z . zdist > window_available z . zwindow then error Invalid_data ; z . zstate <- ( if z . zdist = 1 then DistOne else Dist ) Dist ; inflate_loop z |
let inflate_data z s pos len = if pos < 0 || len < 0 || pos + len > Bytes . length s then invalid_arg " inflate_data " ; z . zneeded <- len ; z . zoutpos <- pos ; z . zoutput <- s ; try if len > 0 then inflate_loop z ; len - z . zneeded with IO . No_more_input -> error Truncated_data |
let inflate_init ( ? header = true ) true ch = { zfinal = false ; zhuffman = fixed_huffman ; zhuffdist = None ; zlen = 0 ; zdist = 0 ; zstate = ( if header then Head else Block ) Block ; zinput = ch ; zbits = 0 ; znbits = 0 ; zneeded = 0 ; zoutput = Bytes . empty ; zoutpos = 0 ; zlengths = Array . make 19 ( - 1 ) 1 ; zwindow = window_create ( 1 lsl 15 ) 15 } |
let inflate ( ? header = true ) true ch = let z = inflate_init ~ header ch in let s = Bytes . create 1 in IO . create_in ~ read ( : fun ( fun ) fun -> let l = inflate_data z s 0 1 in if l = 1 then Bytes . unsafe_get s 0 else raise IO . No_more_input ) ~ input ( : fun s p l -> let n = inflate_data z s p l in if n = 0 then raise IO . No_more_input ; n ) ~ close ( : fun ( ) -> IO . close_in ch ) |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.