text
stringlengths 0
601k
|
---|
type a = { a : b } [ @@ unboxed ] |
let rec a = { a = ( if Sys . opaque_identity true then X a else Y ) } ; ; [ %% expect { | |
type a = { a : b ; } [ @@ unboxed ] } ] ; ; | |
type d = D of e [ %% expect { | |
type d = D of e } ] ; ; | |
let rec d = D ( if Sys . opaque_identity true then V d else W ) ; ; [ %% expect { | } ] ; ; | |
type d = D of e [ @@ unboxed ] |
let rec d = D ( if Sys . opaque_identity true then V d else W ) ; ; [ %% expect { | |
type d = D of e [ @@ unboxed ] } ] ; ; | |
module Transform = struct let pass_name = " unbox - closures " let precondition ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = ! Clflags . unbox_closures && not ( E . at_toplevel env ) && not ( Variable . Map . is_empty set_of_closures . free_vars ) let what_to_specialise ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = let what_to_specialise = W . create ~ set_of_closures in if not ( precondition ~ env ~ set_of_closures ) then what_to_specialise else begin let round = E . round env in let num_closure_vars = Variable . Map . cardinal set_of_closures . free_vars in let module B = Inlining_cost . Benefit in let saved_by_not_building_closure = B . remove_prims ( B . remove_call B . zero ) num_closure_vars in Flambda_iterators . fold_function_decls_ignoring_stubs set_of_closures ~ init : what_to_specialise ~ f ( : fun ~ fun_var ( ~ function_decl : Flambda . function_declaration ) what_to_specialise -> let body_size = Inlining_cost . lambda_size function_decl . body in let small_enough_to_duplicate = let module W = Inlining_cost . Whether_sufficient_benefit in let wsb = W . create_estimate ~ original_size : 0 ~ toplevel : false ~ branch_depth : 0 ~ new_size ( ( : body_size / ! Clflags . unbox_closures_factor ) + 1 ) ~ benefit : saved_by_not_building_closure ~ lifting : false ~ round in W . evaluate wsb in let what_to_specialise = if small_enough_to_duplicate then W . make_direct_call_surrogate_for what_to_specialise ~ fun_var else what_to_specialise in let bound_by_the_closure = Flambda_utils . variables_bound_by_the_closure ( Closure_id . wrap fun_var ) set_of_closures . function_decls in Variable . Set . fold ( fun inner_free_var what_to_specialise -> W . new_specialised_arg what_to_specialise ~ fun_var ~ group : inner_free_var ~ definition ( : Existing_inner_free_var inner_free_var ) ) bound_by_the_closure what_to_specialise ) end end |
let ( ) = Pass_wrapper . register ~ pass_name |
let add_lifted_projections_around_set_of_closures ~ set_of_closures ~ existing_inner_to_outer_vars ~ benefit ~ definitions_indexed_by_new_inner_vars = let body = Flambda_utils . name_expr ( Set_of_closures set_of_closures ) ~ name : Internal_variable_names . unbox_free_vars_of_closures in Variable . Map . fold ( fun new_inner_var ( projection : Projection . t ) ( expr , benefit ) -> let find_outer_var inner_var = match Variable . Map . find inner_var existing_inner_to_outer_vars with | ( outer_var : Flambda . specialised_to ) -> outer_var . var | exception Not_found -> Misc . fatal_errorf " ( UFV ) find_outer_var : expected % a \ to be in [ existing_inner_to_outer_vars ] , but it is \ not . ( The projection was : % a ) " Variable . print inner_var Projection . print projection in let benefit = B . add_projection projection benefit in let named : Flambda . named = let projection = Projection . map_projecting_from projection ~ f : find_outer_var in Flambda_utils . projection_to_named projection in let expr = Flambda . create_let ( find_outer_var new_inner_var ) named expr in ( expr , benefit ) ) definitions_indexed_by_new_inner_vars ( body , benefit ) |
let run ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = if not ! Clflags . unbox_free_vars_of_closures then None else let definitions_indexed_by_new_inner_vars , _ , free_vars , done_something = let all_existing_definitions = Variable . Map . fold ( fun _inner_var ( outer_var : Flambda . specialised_to ) all_existing_definitions -> match outer_var . projection with | None -> all_existing_definitions | Some projection -> Projection . Set . add projection all_existing_definitions ) set_of_closures . free_vars Projection . Set . empty in Flambda_iterators . fold_function_decls_ignoring_stubs set_of_closures ~ init ( : Variable . Map . empty , all_existing_definitions , set_of_closures . free_vars , false ) ~ f ( : fun ~ fun_var : _ ~ function_decl result -> let extracted = Extract_projections . from_function_decl ~ env ~ function_decl ~ which_variables : set_of_closures . free_vars in Projection . Set . fold ( fun projection ( ( definitions_indexed_by_new_inner_vars , all_existing_definitions_including_added_ones , additional_free_vars , _done_something ) as result ) -> if Projection . Set . mem projection all_existing_definitions_including_added_ones then begin result end else begin let projecting_from = Projection . projecting_from projection in let new_inner_var = Variable . rename projecting_from in let new_outer_var = Variable . rename projecting_from in let definitions_indexed_by_new_inner_vars = Variable . Map . add new_inner_var projection definitions_indexed_by_new_inner_vars in let all_existing_definitions_including_added_ones = Projection . Set . add projection all_existing_definitions_including_added_ones in let new_outer_var : Flambda . specialised_to = { var = new_outer_var ; projection = Some projection ; } in let additional_free_vars = Variable . Map . add new_inner_var new_outer_var additional_free_vars in definitions_indexed_by_new_inner_vars , all_existing_definitions_including_added_ones , additional_free_vars , true end ) extracted result ) in if not done_something then None else let num_free_vars_before = Variable . Map . cardinal set_of_closures . free_vars in let num_free_vars_after = Variable . Map . cardinal free_vars in assert ( num_free_vars_after > num_free_vars_before ) ; if num_free_vars_after > 2 * num_free_vars_before then None else let set_of_closures = Flambda . create_set_of_closures ~ function_decls : set_of_closures . function_decls ~ free_vars ~ specialised_args : set_of_closures . specialised_args ~ direct_call_surrogates : set_of_closures . direct_call_surrogates in let expr , benefit = add_lifted_projections_around_set_of_closures ~ set_of_closures ~ benefit : B . zero ~ existing_inner_to_outer_vars : set_of_closures . free_vars ~ definitions_indexed_by_new_inner_vars in Some ( expr , benefit ) |
let run ~ env ~ set_of_closures = Pass_wrapper . with_dump ~ ppf_dump ( : Inline_and_simplify_aux . Env . ppf_dump env ) ~ pass_name ~ input : set_of_closures ~ print_input : Flambda . print_set_of_closures ~ print_output ( : fun ppf ( expr , _ ) -> Flambda . print ppf expr ) ~ f ( : fun ( ) -> run ~ env ~ set_of_closures ) |
module Transform = struct let pass_name = " unbox - specialised - args " let precondition ~ env : _ ( ~ set_of_closures : Flambda . set_of_closures ) = ! Clflags . unbox_specialised_args && not ( Variable . Map . is_empty set_of_closures . specialised_args ) let what_to_specialise ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = let what_to_specialise = W . create ~ set_of_closures in if not ( precondition ~ env ~ set_of_closures ) then what_to_specialise else let projections_by_function = Variable . Map . filter_map set_of_closures . function_decls . funs ~ f ( : fun _fun_var ( function_decl : Flambda . function_declaration ) -> if function_decl . stub then None else Some ( Extract_projections . from_function_decl ~ env ~ function_decl ~ which_variables : set_of_closures . specialised_args ) ) in let invariant_params_flow = Invariant_params . invariant_param_sources set_of_closures . function_decls ~ backend ( : Inline_and_simplify_aux . Env . backend env ) in Variable . Map . fold ( fun fun_var extractions what_to_specialise -> Projection . Set . fold ( fun ( projection : Projection . t ) what_to_specialise -> let group = Projection . projecting_from projection in assert ( Variable . Map . mem group set_of_closures . specialised_args ) ; let what_to_specialise = W . new_specialised_arg what_to_specialise ~ fun_var ~ group ~ definition ( : Projection_from_existing_specialised_arg projection ) in match Variable . Map . find group invariant_params_flow with | exception Not_found -> what_to_specialise | flow -> Variable . Pair . Set . fold ( fun ( target_fun_var , target_spec_arg ) what_to_specialise -> if Variable . equal fun_var target_fun_var || not ( Variable . Map . mem target_spec_arg set_of_closures . specialised_args ) then begin what_to_specialise end else begin let projection = Projection . map_projecting_from projection ~ f ( : fun var -> assert ( Variable . equal var group ) ; target_spec_arg ) in W . new_specialised_arg what_to_specialise ~ fun_var : target_fun_var ~ group ~ definition : ( Projection_from_existing_specialised_arg projection ) end ) flow what_to_specialise ) extractions what_to_specialise ) projections_by_function what_to_specialise end |
module Float = struct type _ t = | IO : int option t | F : float t let bar : type a . a t -> float -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : float t ) f i = let r = ref 0 . in r := bar t f i end |
module Int32 = struct type _ t = | IO : int option t | F : int32 t let bar : type a . a t -> int32 -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : int32 t ) f i = let r = ref 0l in r := bar t f i end |
module Int64 = struct type _ t = | IO : int option t | F : int64 t let bar : type a . a t -> int64 -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : int64 t ) f i = let r = ref 0L in r := bar t f i end |
module Nativeint = struct type _ t = | IO : int option t | F : nativeint t let bar : type a . a t -> nativeint -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : nativeint t ) f i = let r = ref 0n in r := bar t f i end |
let kasprintf k fmt = Format . ( kfprintf ( fun _ -> k ( flush_str_formatter ( ) ) ) str_formatter fmt ) |
let invalid_arg fmt = kasprintf invalid_arg ( " Nocrypto : " ^^ fmt ) |
let failwith fmt = kasprintf failwith ( " Nocrypto : " ^^ fmt ) |
let ( ) // x y = if y < 1 then raise Division_by_zero else if x > 0 then 1 + ( ( x - 1 ) / y ) else 0 [ @@ inline ] |
let imin ( a : int ) b = if a < b then a else b |
let imax ( a : int ) b = if a < b then b else a |
let ( . ) & f g = fun h -> f ( g h ) |
let id x = x |
let rec until p f = let r = f ( ) in if p r then r else until p f |
module Option = struct let get_or f x = function None -> f x | Some y -> y let ( ) >>= a fb = match a with Some x -> fb x | _ -> None let ( ) >>| a f = match a with Some x -> Some ( f x ) | _ -> None let v_map ~ def ~ f = function | Some x -> f x | None -> def let get ~ def = function | Some x -> x | None -> def let map ~ f = function | Some x -> Some ( f x ) | None -> None let cond ~ f = function | Some x -> ignore ( f x ) | None -> ( ) end |
type ' a iter = ( ' a -> unit ) -> unit |
let iter1 a f = f a |
let iter2 a b f = f a ; f b |
let iter3 a b c f = f a ; f b ; f c |
let string_fold ~ f ~ z str = let st = ref z in ( String . iter ( fun c -> st := f ! st c ) str ; ! st ) |
module Z = struct include Z let two = ~$ 2 let three = ~$ 3 let pp = pp_print open Sexplib . Conv let sexp_of_t z = sexp_of_string ( Z . to_string z ) let t_of_sexp s = Z . of_string ( string_of_sexp s ) end |
module Cs = struct open Cstruct let empty = create 0 let null cs = len cs = 0 let ( ) <+> = append let ct_eq cs1 cs2 = let rec go ok i = function | n when n >= 8 -> go ( LE . ( get_uint64 cs1 i = get_uint64 cs2 i ) && ok ) ( i + 8 ) ( n - 8 ) | n when n >= 4 -> go ( LE . ( get_uint32 cs1 i = get_uint32 cs2 i ) && ok ) ( i + 4 ) ( n - 4 ) | n when n >= 2 -> go ( LE . ( get_uint16 cs1 i = get_uint16 cs2 i ) && ok ) ( i + 2 ) ( n - 2 ) | 1 -> ( get_uint8 cs1 i = get_uint8 cs2 i ) && ok | _ -> ok in let n1 = len cs1 and n2 = len cs2 in go true 0 ( imin n1 n2 ) && n1 = n2 let ct_find_uint8 ( ? off = 0 ) ~ f cs = let rec go acc i = function | 0 -> acc | n -> let acc = match ( acc , f ( get_uint8 cs i ) ) with | ( None , true ) -> Some i | _ -> acc in go acc ( succ i ) ( pred n ) in go None off ( len cs - off ) let clone ( ? off = 0 ) ? len cs = let len = match len with None -> cs . len - off | Some x -> x in let cs ' = create_unsafe len in ( blit cs off cs ' 0 len ; cs ' ) let xor_into src dst n = if n > imin ( len src ) ( len dst ) then invalid_arg " Uncommon . Cs . xor_into : buffers to small ( need % d ) " n else Native . xor_into src . buffer src . off dst . buffer dst . off n let xor cs1 cs2 = let len = imin ( len cs1 ) ( len cs2 ) in let cs = clone ~ len cs2 in ( xor_into cs1 cs len ; cs ) let create ( ? init = 0x00 ) n = let cs = create_unsafe n in ( memset cs init ; cs ) let is_prefix cs0 cs = cs0 . len <= cs . len && equal cs0 ( sub cs 0 cs0 . len ) let set_msb bits cs = if bits > 0 then let n = len cs in let rec go width = function | i when i = n -> ( ) | i when width < 8 -> set_uint8 cs i ( get_uint8 cs i lor ( 0xff lsl ( 8 - width ) ) ) | i -> set_uint8 cs i 0xff ; go ( width - 8 ) ( succ i ) in go bits 0 let split2 cs l = ( sub cs 0 l , sub cs l ( len cs - l ) ) let split3 cs l1 l2 = let l12 = l1 + l2 in ( sub cs 0 l1 , sub cs l1 l2 , sub cs l12 ( len cs - l12 ) ) let rpad cs size x = let l = len cs and cs ' = Cstruct . create_unsafe size in if size < l then invalid_arg " Uncommon . Cs . rpad : size < len " ; blit cs 0 cs ' 0 l ; memset ( sub cs ' l ( size - l ) ) x ; cs ' let lpad cs size x = let l = len cs and cs ' = Cstruct . create_unsafe size in if size < l then invalid_arg " Uncommon . Cs . lpad : size < len " ; blit cs 0 cs ' ( size - l ) l ; memset ( sub cs ' 0 ( size - l ) ) x ; cs ' let of_bytes , of_int32s , of_int64s = let aux k set xs = let cs = Cstruct . create_unsafe @@ List . length xs * k in List . iteri ( fun i x -> set cs ( i * k ) x ) xs ; cs in ( aux 1 set_uint8 , aux 4 BE . set_uint32 , aux 8 BE . set_uint64 ) let b x = let cs = Cstruct . create_unsafe 1 in ( set_uint8 cs 0 x ; cs ) let rec shift_left_inplace cs = function | 0 -> ( ) | bits when bits mod 8 = 0 -> let off = bits / 8 in blit cs off cs 0 ( cs . len - off ) ; memset ( shift cs ( cs . len - off ) ) 0x00 | bits when bits < 8 -> let foo = 8 - bits in for i = 0 to cs . len - 2 do let b1 = get_uint8 cs i and b2 = get_uint8 cs ( i + 1 ) in set_uint8 cs i ( ( b1 lsl bits ) lor ( b2 lsr foo ) ) done ; set_uint8 cs ( cs . len - 1 ) @@ get_uint8 cs ( cs . len - 1 ) lsl bits | bits -> shift_left_inplace cs ( 8 * ( bits / 8 ) ) ; shift_left_inplace cs ( bits mod 8 ) let rec shift_right_inplace cs = function | 0 -> ( ) | bits when bits mod 8 = 0 -> let off = bits / 8 in blit cs 0 cs off ( cs . len - off ) ; memset ( sub cs 0 off ) 0x00 | bits when bits < 8 -> let foo = 8 - bits in for i = cs . len - 1 downto 1 do let b1 = get_uint8 cs i and b2 = get_uint8 cs ( i - 1 ) in set_uint8 cs i ( ( b2 lsl foo ) lor ( b1 lsr bits ) ) done ; set_uint8 cs 0 @@ get_uint8 cs 0 lsr bits | bits -> shift_right_inplace cs ( 8 * ( bits / 8 ) ) ; shift_right_inplace cs ( bits mod 8 ) let of_hex str = let hexdigit = function | ' a ' . . ' f ' as x -> int_of_char x - 87 | ' A ' . . ' F ' as x -> int_of_char x - 55 | ' 0 ' . . ' 9 ' as x -> int_of_char x - 48 | x -> invalid_arg " of_hex : ` % c ' " x in let whitespace = function ' ' | ' \ t ' | ' \ r ' | ' \ n ' -> true | _ -> false in match string_fold ~ f ( : fun ( cs , i , acc ) -> function | char when whitespace char -> ( cs , i , acc ) | char -> match ( acc , hexdigit char ) with | ( None , x ) -> ( cs , i , Some ( x lsl 4 ) ) | ( Some y , x ) -> set_uint8 cs i ( x lor y ) ; ( cs , succ i , None ) ) ~ z ( : create_unsafe ( String . length str ) , 0 , None ) str with | ( _ , _ , Some _ ) -> invalid_arg " of_hex : dangling nibble " | ( cs , i , _ ) -> sub cs 0 i let ( lsl ) cs bits = let cs ' = clone cs in shift_left_inplace cs ' bits ; cs ' and ( lsr ) cs bits = let cs ' = clone cs in shift_right_inplace cs ' bits ; cs ' and ( lxor ) cs1 cs2 = xor cs1 cs2 end |
module Array = struct include Array let mem x arr = let rec scan = function | - 1 -> false | n -> arr . ( n ) = x || scan ( pred n ) in scan ( Array . length arr - 1 ) end |
module List = struct include List let find_opt p xs = try Some ( find p xs ) with Not_found -> None end |
let bracket ~ init ~ fini f = let a = init ( ) in match f a with | exception exn -> fini a ; raise exn | res -> fini a ; res |
let pp_xd_gen getu8 len ( ? address = true ) ( ? ascii = false ) ( ? w = 16 ) ( ) ppf = let open Format in let rec blocks f off xs = let n = len xs - off in f off ( min n w ) xs ; if n > w then blocks f ( off + w ) xs in let line ppf off n xs = let iter f = for i = 0 to n - 1 do f i ( off + i |> getu8 xs ) done and spaces n = for _ = 1 to n do pp_print_char ppf ' ' done in if off > 0 then pp_print_cut ppf ( ) ; if address then fprintf ppf " % 04x : " off ; iter ( fun i u8 -> pp_print_string ppf ( if i > 0 then if i mod 8 = 0 then " " else " " else " " ) ; fprintf ppf " % 02x " u8 ) ; if ascii then let llen x = x * 2 + ( x - 1 |> max 0 ) + ( x - 1 ) / 8 in spaces ( 2 + llen w - llen n ) ; iter ( fun _ u8 -> fprintf ppf " % c " ( if u8 >= 0x20 && u8 < 0x7f then Char . chr u8 else ' . ' ) ) ; spaces ( w - n ) in fprintf ppf " [ @< v >% a ] " @ ( fun ppf -> blocks ( line ppf ) 0 ) |
let xd = Cstruct . ( pp_xd_gen get_uint8 len ) |
let xdb = Bytes . ( pp_xd_gen ( fun b i -> Char . code ( get b i ) ) length ) |
module Boot = struct exception Unseeded_generator end |
type action = | Insert of action_insert | Delete of action_delete | Begin_block of string | End_block of string | Func of ( ( unit -> bool ) * ( unit -> bool ) ) mutable pos : int ; mutable length : int ; } mutable text : string ; mutable where : int ; mutable bounds : int * int ; mutable prev : int ; } let undos = Stack . create ( ) in let redos = Stack . create ( ) in object ( self ) val undo = new signal ( ) val redo = new signal ( ) val can_undo_changed = new signal ( ) val can_redo_changed = new signal ( ) val text_buffer = buffer # as_buffer val mutable current_block_name = " " val mutable current_stack = undos val mutable pending_action : action option = None ; val mutable enabled = false val mutable sign_insert = buffer # connect # insert_text ~ callback ( : fun _ _ -> ( ) ) val mutable sign_delete = buffer # connect # delete_range ~ callback ( : fun ~ start : _ ~ stop : _ -> ( ) ) initializer GtkSignal . disconnect text_buffer sign_insert ; GtkSignal . disconnect text_buffer sign_delete ; ignore ( buffer # connect # begin_user_action ~ callback : begin fun ( ) -> if enabled then begin current_stack <- undos ; Stack . clear redos ; can_redo_changed # call self # can_redo ; end end ) ; sign_insert <- buffer # connect # insert_text ~ callback : begin fun start text -> let length = Glib . Utf8 . length text in try let insert_action = match [ @ warning " - 4 " ] pending_action with | Some ( ( Insert a ) as pending ) when start # equal ( buffer # get_iter ( ` OFFSET a . pos ) ) -> if length > 1 || text = " \ n " then begin self # push pending ( a . pos , a . pos ) ; let pos = start # offset + length in self # push ( Insert { pos = pos ; length = length } ) ( pos , pos ) ; pending_action <- None ; raise Exit end else a | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) ; { pos = start # offset ; length = 0 } | Some ( ( Delete a ) as pending ) -> self # push pending ( a . where , a . where ) ; { pos = start # offset ; length = 0 } | None -> { pos = start # offset ; length = 0 } | _ -> assert false in insert_action . pos <- start # offset + length ; insert_action . length <- insert_action . length + length ; pending_action <- Some ( Insert insert_action ) ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; with Exit -> ( ) end ; sign_delete <- buffer # connect # delete_range ~ callback : begin fun ~ start ~ stop -> let delete_action = match [ @ warning " - 4 " ] pending_action with | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) ; { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } | Some ( ( Delete action ) as pending ) -> let prev = buffer # get_iter ( ` OFFSET action . prev ) in if not ( start # equal prev ) && not ( stop # equal prev ) then begin self # push pending ( action . where , action . where ) ; { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } end else begin action . prev <- start # offset ; action end | None -> { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } | _ -> assert false in pending_action <- Some ( Delete delete_action ) ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; let b1 , b2 = buffer # selection_bounds in if b1 # equal start && b2 # equal stop then begin let text = buffer # get_text ~ start ~ stop ( ) in let length = Glib . Utf8 . length text in delete_action . text <- text ; delete_action . bounds <- ( length , 0 ) ; self # push ( Delete delete_action ) ( start # offset , start # offset ) ; end else if ( start # equal ( buffer # get_iter ` INSERT ) ) then begin delete_action . text <- delete_action . text ^ ( buffer # get_text ~ start ~ stop ( ) ) ; delete_action . bounds <- ( let b = fst delete_action . bounds in ( b , b ) ) ; end else begin let text = buffer # get_text ~ start ~ stop ( ) in let length = Glib . Utf8 . length text in delete_action . text <- text ^ delete_action . text ; let b1 = ( fst delete_action . bounds ) + length in let b2 = if length = 1 then b1 else 0 in delete_action . bounds <- ( b1 , b2 ) ; delete_action . where <- start # offset ; end ; end ; ignore ( self # connect # undo ~ callback ( : fun ~ name : _ -> self # pop undos ) ) ; ignore ( self # connect # redo ~ callback ( : fun ~ name : _ -> self # pop redos ) ) ; self # disable ( ) ; method private push pending ( b1 , b2 ) = Stack . push ( pending , b1 , b2 ) current_stack ; pending_action <- None ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; method private push_pending_action ( ) = match [ @ warning " - 4 " ] pending_action with | None -> ( ) | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) | Some ( ( Delete a ) as pending ) -> self # push pending ( a . where , a . where ) | _ -> assert false method private pop ( ? in_block = false ) stack = let ( action , b1 , b2 ) = Stack . pop stack in current_stack <- ( if stack == undos then redos else undos ) ; begin match action with | Insert action -> let stop = buffer # get_iter ( ` OFFSET action . pos ) in buffer # delete ~ start ( : stop # backward_chars action . length ) ~ stop ; if in_block then ( self # pop ~ in_block stack ) try begin match Stack . top stack with | Insert _ , _ , _ -> self # pop stack | _ -> ( ) end ; with Stack . Empty -> ( ) end ) * | Delete action -> let iter = buffer # get_iter ( ` OFFSET b1 ) in buffer # insert ~ iter action . text ; let where = buffer # get_iter ( ` OFFSET b1 ) in if stack == undos then begin let b1 , b2 = action . bounds in buffer # select_range ( where # forward_chars b1 ) ( where # forward_chars b2 ) ; end ; if in_block then ( self # pop ~ in_block stack ) | End_block name -> self # push ( Begin_block name ) ( b1 , b2 ) ; self # pop ~ in_block : true stack ; | Begin_block name -> self # push_pending_action ( ) ; self # push ( End_block name ) ( b1 , b2 ) ; buffer # select_range ( buffer # get_iter ( ` OFFSET b1 ) ) ( buffer # get_iter ( ` OFFSET b2 ) ) ; ( assert in_block ) ; | Func ( f , g ) -> buffer # select_range ( buffer # get_iter ( ` OFFSET b1 ) ) ( buffer # get_iter ( ` OFFSET b2 ) ) ; self # disable ( ) ; let action = if stack == undos then ( ignore ( g ( ) ) ; ( Func ( g , f ) ) ) else ( ignore ( f ( ) ) ; ( Func ( f , g ) ) ) in self # push action ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; self # enable ( ) ; end ; self # push_pending_action ( ) ; current_stack <- stack ; can_undo_changed # call self # can_undo ; can_redo_changed # call self # can_redo ; method private revert stack = if enabled then begin self # push_pending_action ( ) ; if current_block_name <> " " then ( self # end_block ( ) ) ; if Stack . is_empty stack then begin false end else begin let ins = ( buffer # get_iter ` INSERT ) in let sel = ( buffer # get_iter ` SEL_BOUND ) in let block_name , b1 , b2 = match [ @ warning " - 4 " ] Stack . top stack with | ( Begin_block name ) , b1 , b2 -> name , b1 , b2 | ( End_block name ) , b1 , b2 -> name , b1 , b2 | _ , b1 , b2 -> " " , b1 , b2 in let b1 , b2 = ( buffer # get_iter ( ` OFFSET b1 ) ) , ( buffer # get_iter ( ` OFFSET b2 ) ) in if ins # equal b1 && sel # equal b2 then begin if stack == undos then ( undo # call block_name ) else ( redo # call block_name ) ; true end else begin buffer # select_range b1 b2 ; false end ; end ; end else false method begin_block ~ name = if enabled && current_block_name = " " then self # push_pending_action ( ) ; buffer # begin_user_action ( ) ; current_block_name <- name ; self # push ( Begin_block name ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; method end_block ( ) = if enabled && current_block_name <> " " then self # push_pending_action ( ) ; begin match [ @ warning " - 4 " ] Stack . top current_stack with | ( Begin_block name ) , _ , _ when name = current_block_name -> ignore ( Stack . pop current_stack ) | _ -> self # push ( End_block current_block_name ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; end ; current_block_name <- " " ; buffer # end_user_action ( ) ; method func f ~ inverse = if enabled then self # push_pending_action ( ) ; buffer # begin_user_action ( ) ; self # disable ( ) ; if f ( ) then begin self # push ( Func ( f , inverse ) ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; end ; self # enable ( ) ; buffer # end_user_action ( ) ; method enable ( ) = enabled <- true ; GtkSignal . handler_unblock text_buffer sign_delete ; GtkSignal . handler_unblock text_buffer sign_insert ; method disable ( ) = self # push_pending_action ( ) ; enabled <- false ; GtkSignal . handler_block text_buffer sign_delete ; GtkSignal . handler_block text_buffer sign_insert ; method is_enabled = enabled method can_undo = ( not ( Stack . is_empty undos ) ) || ( match pending_action with Some _ when current_stack == undos -> true | _ -> false ) method can_redo = ( not ( Stack . is_empty redos ) ) || ( match pending_action with Some _ when current_stack == redos -> true | _ -> false ) method redo ( ) = self # revert redos method undo ( ) = self # revert undos method length = Stack . length undos , Stack . length redos method connect = new manager_signals ~ undo ~ redo ~ can_undo_changed ~ can_redo_changed end object inherit ml_signals [ undo # disconnect ; redo # disconnect ; can_undo_changed # disconnect ; can_redo_changed # disconnect ] method can_undo_changed ~ callback = can_undo_changed # connect ~ after ~ callback method can_redo_changed ~ callback = can_redo_changed # connect ~ after ~ callback method undo ~ callback = undo # connect ~ after ~ callback ( : fun name -> callback ~ name ) method redo ~ callback = redo # connect ~ after ~ callback ( : fun name -> callback ~ name ) end |
let title = " Built - in signer using raw unencrypted keys . " |
let description = " Please DO NOT USE this signer outside of test environments . \ n \ Valid secret key URIs are of the form \ n \ \ - unencrypted :< key >\ n \ where < key > is the secret key in Base58 . \ n \ Valid public key URIs are of the form \ n \ \ - unencrypted :< public_key >\ n \ where < public_key > is the public key in Base58 . " |
let secret_key sk_uri = Lwt . return ( Signature . Secret_key . of_b58check ( Uri . path ( sk_uri : sk_uri :> Uri . t ) ) ) |
let make_sk sk = Client_keys . make_sk_uri ( Uri . make ~ scheme ~ path ( : Signature . Secret_key . to_b58check sk ) ( ) ) |
let make_sapling_key sk = let path = Base58 . simple_encode Tezos_sapling . Core . Wallet . Spending_key . b58check_encoding sk in Client_keys . make_sapling_uri ( Uri . make ~ scheme ~ path ( ) ) |
let public_key pk_uri = Lwt . return ( Signature . Public_key . of_b58check ( Uri . path ( pk_uri : pk_uri :> Uri . t ) ) ) |
let make_pk pk = Client_keys . make_pk_uri ( Uri . make ~ scheme ~ path ( : Signature . Public_key . to_b58check pk ) ( ) ) |
let neuterize sk_uri = secret_key sk_uri >>=? fun sk -> make_pk ( Signature . Secret_key . to_public_key sk ) >>?= return |
let public_key_hash pk_uri = public_key pk_uri >>=? fun pk -> return ( Signature . Public_key . hash pk , Some pk ) |
let import_secret_key ~ io : _ = public_key_hash |
let sign ? watermark sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . sign ? watermark sk buf ) |
let deterministic_nonce sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . deterministic_nonce sk buf ) |
let deterministic_nonce_hash sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . deterministic_nonce_hash sk buf ) |
let supports_deterministic_nonces _ = return_true |
type any = Any : ' a -> any |
type any = Any : ' a -> any } ] | |
let Any x = Any ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let Any x = Any ( ) and ( ) = ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let rec Any x = Any ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let [ @ attribute ] Any x = Any ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | ^^^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | ^^^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
type other = Any : _ -> other |
type other = Any : ' a -> other } ] | |
let Any x = Any ( ) ^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let Any x = Any ( ) and ( ) = ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let rec Any x = Any ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let [ @ attribute ] Any x = Any ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^ but the constructor Any introduces existential types . } ] | |
module type Type = sig type text open OOChannel class nfd : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfc : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfkd : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfkc : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel val nfd : text -> text val nfkd : text -> text val nfc : text -> text val nfkc : text -> text module NFCBuf : sig type buf val create : int -> buf val contents : buf -> text val clear : buf -> unit val reset : buf -> unit val add_char : buf -> UChar . t -> unit val add_string : buf -> text -> unit val add_buffer : buf -> buf -> unit end val nfc_append : text -> text -> text val put_nfd : XString . t -> text -> unit val put_nfkd : XString . t -> text -> unit val put_nfc : XString . t -> text -> unit val put_nfkc : XString . t -> text -> unit type index val nfd_inc : text -> index -> ( [ ` Inc of UChar . t list * index * ' a lazy_t ] as ' a ) ' a val canon_compare : text -> text -> int val nfd_decompose : UChar . t -> UChar . t list val nfkd_decompose : UChar . t -> UChar . t list end |
module Make ( Config : ConfigInt . Type ) Type ( Text : UnicodeString . Type ) Type = struct module UInfo = UCharInfo . Make ( MakeConfig ) MakeConfig let null = UChar . chr_of_uint 0 let decomposition_tbl = UInfo . load_decomposition_tbl ( ) let decomposition u = UCharTbl . get decomposition_tbl u let composition_exclusion_tbl = UInfo . load_composition_exclusion_tbl ( ) let composition_exclusion u = UCharTbl . Bool . get composition_exclusion_tbl u let composition_tbl = UInfo . load_composition_tbl ( ) let composition u = UCharTbl . get composition_tbl u let rec add_list x = function [ ] -> ( ) | u :: r -> XString . add_char x u ; add_list x r let shiftright x i j = for k = j downto i do XString . set x ( k + 1 ) 1 ( XString . get x k ) k done let rotate x i j = let u = XString . get x j in shiftright x i ( j - 1 ) 1 ; XString . set x i u let blit x i x ' i ' len = for k = 0 to len - 1 do XString . set x ' ( i ' + k ) k ( XString . get x ( i + k ) k ) k ; done let nfd u = match decomposition u with ` HangulSyllable -> Hangul . decompose u | ` Composite ( ` Canon , d ) d -> d | _ -> [ u ] u let nfd_decompose = nfd let rec nfkd u = match decomposition u with ` HangulSyllable -> Hangul . decompose u | ` Composite ( _ , d ) d -> List . fold_right ( fun u a -> ( nfkd u ) u @ a ) a d [ ] | ` Canonform -> [ u ] u let nfkd_decompose = nfkd let canon_decompose_uchar x u = match decomposition u with ` HangulSyllable -> Hangul . add_decomposition x u | ` Composite ( ` Canon , d ) d -> add_list x d | _ -> XString . add_char x u class canon_decompose ( c_out : UChar . t OOChannel . obj_output_channel ) obj_output_channel = object method put u = List . iter c_out # put ( nfd u ) u method close_out = c_out # close_out method flush ( ) = c_out # flush ( ) end let rec kompat_decompose_uchar x u = match decomposition u with ` Composite ( _ , d ) d -> List . iter ( kompat_decompose_uchar x ) x d | _ -> Hangul . add_decomposition x u class kompat_decompose c_out : [ UChar . t ] t OOChannel . obj_output_channel = object method put u = List . iter c_out # put ( nfkd u ) u method close_out = c_out # close_out method flush ( ) = c_out # flush ( ) end let canon_reorder x = let chead = ref 0 in let pos = ref 0 in for i = 0 to XString . length x - 1 do let u = XString . get x i in let c = UInfo . combined_class u in if c = 0 then chead := i else begin pos := i - 1 ; while ! pos >= ! chead && UInfo . combined_class ( XString . get x ! pos ) pos > c do decr pos done ; rotate x ( ! pos + 1 ) 1 i end done class canon_reorder c_out : [ UChar . t ] t OOChannel . obj_output_channel = object ( self ) self val mutable sq = [ ] method private out_buf = let sq ' = List . stable_sort ( fun ( c1 , _ ) _ ( c2 , _ ) _ -> c1 - c2 ) c2 sq in List . iter ( fun ( _ , u ) u -> c_out # put u ) u sq ' ; sq <- [ ] method put u = let c = UInfo . combined_class u in if c = 0 then ( if sq <> [ ] then self # out_buf ; c_out # put u ) u else sq <- ( c , u ) u :: sq method close_out ( ) = self # out_buf ; c_out # close_out ( ) method flush ( ) = if sq <> [ ] then failwith " uNF . canon_reorder # flush : \ Cannot flush the entire buffer " ; c_out # flush ( ) end let rec look_composition u1 = function [ ] -> None | ( u , u ' ) u ' :: _ when u = u1 -> if composition_exclusion u ' || UInfo . combined_class u ' <> 0 then None else Some u ' | _ :: rest -> look_composition u1 rest let rec canon_compose_loop x i j x ' k c ' = if j >= XString . length x then begin blit x i x ' ( k + 1 ) 1 ( XString . length x - i ) i ; k + max ( XString . length x - i ) i 0 end else let u = XString . get x j in let c = UInfo . combined_class u in let b = if j = i || c ' <> c then match look_composition u ( composition ( XString . get x ' k ) k ) k with None -> true | Some u ' -> XString . set x ' k u ' ; shiftright x i ( j - 1 ) 1 ; false else true in if b && c = 0 then begin blit x i x ' ( k + 1 ) 1 ( j - i + 1 ) 1 ; canon_compose_loop x ( j + 1 ) 1 ( j + 1 ) 1 x ' ( k + 1 + j - i ) i 0 end else let i ' = if b then i else i + 1 in let c ' = if b then c else c ' in canon_compose_loop x i ' ( j + 1 ) 1 x ' k c ' let canon_compose x ' x = if XString . length x = 0 then ( ) else let pos = ref 0 in while ! pos < XString . length x && UInfo . combined_class ( XString . get x ! pos ) pos <> 0 do incr pos done ; blit x 0 x ' 0 ! pos ; if ! pos < XString . length x then begin XString . set x ' ! pos ( XString . get x ! pos ) pos ; pos := canon_compose_loop x ( ! pos + 1 ) 1 ( ! pos + 1 ) 1 x ' ! pos 0 end else ( ) ; XString . shrink x ' ( ! pos + 1 ) 1 class canon_compose c_out : [ UChar . t ] t OOChannel . obj_output_channel = object ( self ) self val mutable has_strt = false val mutable strt = null val mutable cmp_cnd = [ ] val mutable lst_cc = - 1 val sq = Queue . create ( ) method private set_strt u = if has_strt then c_out # put strt ; Queue . iter c_out # put sq ; strt <- u ; has_strt <- true ; cmp_cnd <- composition u ; lst_cc <- - 1 ; Queue . clear sq method private output_buffer ( ) = if has_strt then c_out # put strt ; Queue . iter c_out # put sq ; method put u = let c = UInfo . combined_class u in if not has_strt then if c = 0 then self # set_strt u else c_out # put u else if c = lst_cc then Queue . add u sq else match look_composition u cmp_cnd with Some u ' -> strt <- u ' | None -> if c = 0 then self # set_strt u else begin Queue . add u sq ; lst_cc <- c end method close_out ( ) = self # output_buffer ( ) ; c_out # close_out ( ) method flush ( ) = self # output_buffer ( ) ; c_out # flush ( ) end class nfd c_out = let c = new canon_reorder c_out in object inherit canon_decompose c end class nfc c_out = let c = new canon_compose c_out in let c = new canon_reorder c in object inherit canon_decompose c method ! flush = c_out # flush end class nfkd c_out = let c = new canon_reorder c_out in object inherit kompat_decompose c method ! flush = c_out # flush end class nfkc c_out = let c = new canon_compose c_out in let c = new canon_reorder c in object inherit kompat_decompose c method ! flush = c_out # flush end type inc = [ ` Inc of UChar . t list * Text . index * ' a lazy_t ] lazy_t as ' a let rec inc_end i = ` Inc ( [ ] , i , lazy ( inc_end i ) i ) i let rec inc_canon_decompose t i : inc = if Text . out_of_range t i then inc_end i else let i ' = Text . next t i in ` Inc ( nfd ( Text . look t i ) i , i ' , lazy ( inc_canon_decompose t i ' ) i ' ) i ' let rec canon_insert_list ( ( _ , c ) c as x ) x a = match a with [ ] -> [ x ] x | ( _ , c ' ) c ' as y :: rest -> if c ' <= c then y :: canon_insert_list x rest else x :: a let rec split1_list = function [ ] -> [ ] | ( x , _ ) _ :: rest -> x :: split1_list rest let canon_sort_list sq = let rec loop a = function [ ] -> split1_list a | ( u , 0 ) 0 :: rest -> ( split1_list a ) a @ ( u :: ( loop [ ] rest ) rest ) rest | ( _ , _ ) _ as x :: rest -> loop ( canon_insert_list x a ) a rest in loop [ ] sq let rec read_combined_class = function [ ] -> [ ] | u :: rest -> ( u , UInfo . combined_class u ) u :: read_combined_class rest let inc_reorder f t i = let ` Inc ( us , i ' , f ) f = f t i in let rec loop ( f : inc Lazy . t ) t a i = let ` Inc ( us , i ' , f ) f = Lazy . force f in let a ' = read_combined_class us in match a ' with [ ] -> ` Inc ( canon_sort_list a , i , lazy ( inc_end i ) i ) i | ( _ , 0 ) 0 :: _ -> ` Inc ( canon_sort_list a , i , lazy ( loop f a ' i ' ) i ' ) i ' | _ -> loop f ( a @ a ' ) a ' i ' in loop f ( read_combined_class us ) us i ' let nfd_inc t i = inc_reorder inc_canon_decompose t i let canon_compare t1 t2 = let ` Inc ( Incus1 , _ , f1 ) f1 = nfd_inc t1 ( Text . nth t1 0 ) 0 in let ` Inc ( Incus2 , _ , f2 ) f2 = nfd_inc t2 ( Text . nth t2 0 ) 0 in let rec loop us1 us2 f1 f2 = match us1 , us2 with [ ] , [ ] -> 0 | [ ] , _ -> ~- 1 | _ , [ ] -> 1 | u1 :: r1 , u2 :: r2 -> let sgn = UChar . compare u1 u2 in if sgn <> 0 then sgn else let us1 , f1 = if r1 = [ ] then let ` Inc ( us1 , _ , f1 ) f1 = Lazy . force f1 in ( us1 , f1 ) f1 else ( r1 , f1 ) f1 in let us2 , f2 = if r2 = [ ] then let ` Inc ( us2 , _ , f2 ) f2 = Lazy . force f2 in ( us2 , f2 ) f2 else ( r2 , f2 ) f2 in loop us1 us2 f1 f2 in loop us1 us2 f1 f2 type text = Text . t type index = Text . index let canon_decompose x t = Text . iter ( canon_decompose_uchar x ) x t let kompat_decompose x t = Text . iter ( kompat_decompose_uchar x ) x t let text_of_xstring x = Text . init ( XString . length x ) x ( XString . get x ) x let nfd t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in canon_decompose x t ; canon_reorder x ; text_of_xstring x let nfkd t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in kompat_decompose x t ; canon_reorder x ; text_of_xstring x let nfc t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in canon_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x ; text_of_xstring x let nfkc t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in kompat_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x ; text_of_xstring x let put_nfd x t = XString . clear x ; canon_decompose x t ; canon_reorder x let put_nfkd x t = XString . clear x ; kompat_decompose x t ; canon_reorder x let put_nfc x t = XString . clear x ; canon_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x let put_nfkc x t = XString . clear x ; kompat_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x module NFCBuf = struct type buf = { mutable normalized : bool ; mutable buf : XString . t } t let create bufsize = { normalized = true ; buf = XString . make ~ bufsize 0 null } null let contents b = ( if not b . normalized then let buf = XString . make 0 null in XString . iter ( canon_decompose_uchar buf ) buf b . buf ; canon_reorder buf ; canon_compose buf buf ; b . buf <- buf ; b . normalized <- true ) true ; text_of_xstring b . buf let clear b = b . normalized <- true ; XString . clear b . buf let reset b = b . normalized <- true ; XString . reset b . buf let add_char b u = b . normalized <- false ; XString . add_char b . buf u let add_string b t = b . normalized <- false ; Text . iter ( XString . add_char b . buf ) buf t let add_buffer b1 b2 = b1 . normalized <- false ; XString . add_xstring b1 . buf b2 . buf end let nfc_append t1 t2 = let b = XString . make 0 null in canon_decompose b t1 ; canon_decompose b t2 ; canon_reorder b ; canon_compose b b ; text_of_xstring b end |
type t = ( Field . t , Field . t Scalar_challenge . t , Other_field . t Shifted_value . t , ( Field . t Scalar_challenge . t Bulletproof_challenge . t , Tock . Rounds . n ) Pickles_types . Vector . t , Field . t , Boolean . var ) Types . Step . Proof_state . Per_proof . In_circuit . t |
module Plonk_checks = struct include Plonk_checks include Plonk_checks . Make ( Shifted_value ) Shifted_value ( Plonk_checks . Scalars . Tock ) Tock end |
module Constant = struct type t = ( Challenge . Constant . t , Challenge . Constant . t Scalar_challenge . t , Tock . Field . t Shifted_value . t , ( Challenge . Constant . t Scalar_challenge . t Bulletproof_challenge . t , Tock . Rounds . n ) Vector . t , Digest . Constant . t , bool ) Types . Step . Proof_state . Per_proof . In_circuit . t let shift = Shifted_value . Shift . create ( module Tock . Field ) Field let dummy ( ) : t = let one_chal = Challenge . Constant . dummy in let open Ro in let alpha = scalar_chal ( ) in let beta = chal ( ) in let gamma = chal ( ) in let zeta = scalar_chal ( ) in let chals : _ Composition_types . Wrap . Proof_state . Deferred_values . Plonk . Minimal . t = { alpha = Common . Ipa . Wrap . endo_to_field alpha ; beta = Challenge . Constant . to_tock_field beta ; gamma = Challenge . Constant . to_tock_field gamma ; zeta = Common . Ipa . Wrap . endo_to_field zeta } in let evals = Tuple_lib . Double . map Dummy . evals_combined . evals ~ f ( : fun e -> e . evals ) evals in let env = Plonk_checks . scalars_env ( module Tock . Field ) Field ~ srs_length_log2 : Common . Max_degree . wrap_log2 ~ endo : Endo . Wrap_inner_curve . base ~ mds : Tock_field_sponge . params . mds ~ field_of_hex : ( Core_kernel . Fn . compose Tock . Field . of_bigint Kimchi_pasta . Pasta . Bigint256 . of_hex_string ) ~ domain : ( Plonk_checks . domain ( module Tock . Field ) Field ( wrap_domains ~ proofs_verified : 2 ) 2 . h ~ shifts : Common . tock_shifts ~ domain_generator : Tock . Field . domain_generator ) chals evals in { deferred_values = { plonk = { ( Plonk_checks . derive_plonk ( module Tock . Field ) Field ~ env ~ shift chals evals ) with alpha ; beta ; gamma ; zeta } ; combined_inner_product = Shifted_value ( tock ( ) ) ; xi = Scalar_challenge . create one_chal ; bulletproof_challenges = Dummy . Ipa . Wrap . challenges ; b = Shifted_value ( tock ( ) ) } ; should_finalize = false ; sponge_digest_before_evaluations = Digest . Constant . dummy } end |
let typ ~ wrap_rounds : ( t , Constant . t ) t Typ . t = Types . Step . Proof_state . Per_proof . In_circuit . spec wrap_rounds |> Spec . typ ( module Impl ) Impl ( Shifted_value . typ Other_field . typ ) typ |> Typ . transport ~ there : Types . Step . Proof_state . Per_proof . In_circuit . to_data ~ back : Types . Step . Proof_state . Per_proof . In_circuit . of_data |> Typ . transport_var ~ there : Types . Step . Proof_state . Per_proof . In_circuit . to_data ~ back : Types . Step . Proof_state . Per_proof . In_circuit . of_data |
let pp_pos ppf d = pp ppf " % d . % d ( :% d , % 06X ) " ( Uutf . decoder_line d ) ( Uutf . decoder_col d ) ( Uutf . decoder_count d ) ( Uutf . decoder_byte_count d ) |
let pp_malformed ppf bs = let l = String . length bs in pp ppf " [ @ malformed bytes [ ( " ; @ if l > 0 then pp ppf " % 02X " ( Char . code ( bs . [ 0 ] ) ) ; for i = 1 to l - 1 do pp ppf " @ % 02X " ( Char . code ( bs . [ i ] ) ) done ; pp ppf " ) ] ] " @@ |
let pp_dump_uchar ppf u = Format . fprintf ppf " U +% 04X " ( Uchar . to_int u ) |
let exec = Filename . basename Sys . executable_name |
let log f = Format . eprintf ( " % s : " ^^ f ^^ " " ) @? exec |
let input_malformed = ref false |
let log_malformed inf d bs = input_malformed := true ; log " % s :% a : % a . " @ inf pp_pos d pp_malformed bs |
let uchar_dump ppf = function |
let uchar_encoder enc = let enc = match enc with ` ISO_8859_1 | ` US_ASCII -> ` UTF_8 | # Uutf . encoding as enc -> enc in let e = Uutf . encoder enc ( ` Channel stdout ) in fun v -> ignore ( Uutf . encode e v ) |
let out_fun ascii oe = if ascii then uchar_dump Format . std_formatter else uchar_encoder oe |
let u_rep = ` Uchar Uutf . u_rep |
let id inf d first_dec out = let rec loop d = function | ` Uchar _ as v -> out v ; loop d ( Uutf . decode d ) | ` End as v -> out v | ` Malformed bs -> log_malformed inf d bs ; out u_rep ; loop d ( Uutf . decode d ) | ` Await -> assert false in if Uutf . decoder_removed_bom d then out ( ` Uchar Uutf . u_bom ) ; loop d first_dec |
let normalize nf inf d first_dec out = let n = Uunf . create nf in let rec add v = match Uunf . add n v with | ` Uchar cp as u -> out u ; add ` Await | ` Await | ` End -> ( ) in let rec loop d = function | ` Uchar _ as v -> add v ; loop d ( Uutf . decode d ) | ` End as v -> add v ; out ` End | ` Malformed bs -> log_malformed inf d bs ; add u_rep ; loop d ( Uutf . decode d ) | ` Await -> assert false in if Uutf . decoder_removed_bom d then add ( ` Uchar Uutf . u_bom ) ; loop d first_dec |
let trip nf inf enc ascii = try let ic = if inf = " " - then stdin else open_in inf in let d = Uutf . decoder ? encoding : enc ( ` Channel ic ) in let first_dec = Uutf . decode d in let out = out_fun ascii ( Uutf . decoder_encoding d ) in begin match nf with | None -> id inf d first_dec out | Some nf -> normalize nf inf d first_dec out end ; if inf <> " " - then close_in ic ; flush stdout ; with Sys_error e -> log " % s . " @ e ; exit 1 |
let unicode_version ( ) = Format . printf " % s . " @ Uunf . unicode_version |
let do_cmd cmd nf inf enc ascii = match cmd with |
let cmd = let doc = " Output supported Unicode version . " in let unicode_version = ` Unicode_version , Arg . info [ " unicode - version " ] ~ doc in Arg . ( value & vflag ` Trip [ unicode_version ] ) |
let nf = let docs = nf_doc in let doc = " Normalization Form D ( NFD ) , canonical decomposition . " in let nfd = Some ` NFD , Arg . info [ " nfd " ] ~ doc ~ docs in let doc = " Normalization Form C ( NFC ) , canonical decomposition followed by \ canonical composition . " in let nfc = Some ` NFC , Arg . info [ " nfc " ] ~ doc ~ docs in let doc = " Normalization form KD ( NFKD ) , compatibility decomposition . " in let nfkd = Some ` NFKD , Arg . info [ " nfkd " ] ~ doc ~ docs in let doc = " Normalization form KC ( NFKC ) , compatibility decomposition \ followed by canonical composition . " in let nfkc = Some ` NFKC , Arg . info [ " nfkc " ] ~ doc ~ docs in Arg . ( value & vflag None [ nfd ; nfc ; nfkd ; nfkc ] ) |
let file = let doc = " The input file . Reads from stdin if unspecified . " in Arg . ( value & pos 0 string " " - & info [ ] ~ doc ~ docv " : FILE " ) |
let enc = let enc = [ " UTF - 8 " , ` UTF_8 ; " UTF - 16 " , ` UTF_16 ; " UTF - 16LE " , ` UTF_16LE ; " UTF - 16BE " , ` UTF_16BE ; " ASCII " , ` US_ASCII ; " latin1 " , ` ISO_8859_1 ] in let doc = strf " Input encoding , must % s . If unspecified the encoding is \ guessed . The output encoding is the same as the input \ encoding except for ASCII and latin1 where UTF - 8 is output . " ( Arg . doc_alts_enum enc ) in Arg . ( value & opt ( some ( enum enc ) ) None & info [ " e " ; " encoding " ] ~ doc ) |
let ascii = let doc = " Output the input text as newline ( U + 000A ) separated Unicode scalar values written in the US - ASCII charset . " in Arg . ( value & flag & info [ " a " ; " ascii " ] ~ doc ) |
let cmd = let doc = " normalize Unicode text " in let man = [ ` S " DESCRIPTION " ; ` P " ( $ tname ) inputs Unicode text from stdin and rewrites it to stdout according to a specified Unicode normalization form ( see UAX 15 ) . " ; ` P " If no normalization form is specified the character stream is left intact . " ; ` P " Invalid byte sequences in the input are reported on stderr and replaced by the Unicode replacement character ( U + FFFD ) in the output . " ; ` S nf_doc ; ` S " OPTIONS " ; ` S " EXIT STATUS " ; ` P " ( $ tname ) exits with one of the following values " ; : ` I ( " 0 " , " no error occurred " ) ; ` I ( " 1 " , " a command line parsing error occurred " ) ; ` I ( " 2 " , " the input text was malformed " ) ; ` S " BUGS " ; ` P " This program is distributed with the Uunf OCaml library . See http :// erratique . ch / software / uunf for contact information . " ] in Term . ( pure do_cmd $ cmd $ nf $ file $ enc $ ascii ) , Term . info " unftrip " ~ version " :%% VERSION " %% ~ doc ~ man |
let ( ) = match Term . eval cmd with |
module Sessions = Hlist . Make ( LinState ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.