text stringlengths 12 786k |
|---|
let unpack_bool value = match unpack_sexp value with | Bool bl -> bl | _ -> arg_type_mismatch " bool " value ; ; |
let unpack_list value = match unpack_sexp value with | List lst -> lst | _ -> arg_type_mismatch " list " value ; ; |
let unpack_input_port value = match value with | Port ( InputPort ( _ , lb , _ ) ) -> lb | _ -> arg_type_mismatch " input - port " value ; ; |
let unpack_input_port_for_channel value = match value with | Port ( InputPort ( _ , _ , channel ) ) -> channel | _ -> arg_type_mismatch " input - port " value ; ; |
let unpack_output_port value = match value with | Port ( OutputPort ( _ , channel ) ) -> channel | _ -> arg_type_mismatch " output - port " value ; ; |
let unpack_chan value = match value with | Chan chan -> chan | _ -> arg_type_mismatch " chan " value ; ; |
let unpack_promise value = match value with | Promise promise -> promise | _ -> arg_type_mismatch " promise " value ; ; |
let with_mutex mutex func = Mutex . lock mutex ; let rst = func ( ) in Mutex . unlock mutex ; rst ; ; |
type t = { by_scope : Simple . t EP . Map . t Scope . Map . t ; combined : Simple . t EP . Map . t } |
let [ @ ocamlformat " disable " ] print ppf { by_scope ; combined ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > by_scope @ % a ) ] @@ \ [ @< hov 1 ( > combined @ % a ) ] @\ ] " @ ( Scope . Map . print ( EP . Map . print Simple . ... |
let empty = { by_scope = Scope . Map . empty ; combined = EP . Map . empty } |
let add t prim ~ bound_to scope = match EP . Map . find prim t . combined with | exception Not_found -> let level = match Scope . Map . find scope t . by_scope with | exception Not_found -> EP . Map . singleton prim bound_to | level -> EP . Map . add prim bound_to level in let by_scope = S... |
let find t prim = match EP . Map . find prim t . combined with | exception Not_found -> None | bound_to -> Some bound_to |
module Rhs_kind : sig type t = | Needs_extra_binding of { bound_to : Simple . t } | Rhs_in_scope of { bound_to : Simple . t } val bound_to : t -> Simple . t include Container_types . S with type t := t type t = | Needs_extra_binding of { bound_to : Simple . t } | Rhs_in_scope of { b... |
let cse_with_eligible_lhs ~ typing_env_at_fork ~ cse_at_each_use ~ params prev_cse ( extra_bindings : EPA . t ) extra_equations = let params = List . map params ~ f : Bound_parameter . name |> Name . Set . of_list in let is_param simple = Simple . pattern_match simple ~ name ( : fun name ... |
let join_one_cse_equation ~ cse_at_each_use prim bound_to_map ( cse , extra_bindings , extra_equations , allowed ) = let has_value_on_all_paths = List . for_all cse_at_each_use ~ f ( : fun ( _ , id , _ ) -> RI . Map . mem id bound_to_map ) in if not has_value_on_all_paths then cse , ... |
let cut_cse_environment { by_scope ; _ } ~ scope_at_fork = let _ , _ , levels = Scope . Map . split scope_at_fork by_scope in Scope . Map . fold ( fun _scope equations result -> EP . Map . disjoint_union equations result ) levels EP . Map . empty |
module Join_result = struct type nonrec t = { cse_at_join_point : t ; extra_params : EPA . t ; extra_equations : T . t Name . Map . t ; extra_allowed_names : Name_occurrences . t } end |
let join0 ~ typing_env_at_fork ~ cse_at_fork ~ cse_at_each_use ~ params ~ scope_at_fork = let params = Bound_parameters . to_list params in let compute_cse_one_round prev_cse extra_params extra_equations ~ allowed = let new_cse = cse_with_eligible_lhs ~ typing_env_at_fork ~ cse_at_each_use ~ params prev_... |
let join ~ typing_env_at_fork ~ cse_at_fork ~ use_info ~ get_typing_env ~ get_rewrite_id ~ get_cse ~ params = let scope_at_fork = TE . current_scope typing_env_at_fork in let seen_equations = ref false in let cse_at_each_use = List . map use_info ~ f ( : fun use -> let t = get_cse use in let cse_be... |
let code = Table . create 0 |
let emit_int i = Table . emit code i |
let ins_mem i c = match i with | Copy ( dst , src ) -> dst :: src :: c | Set dst -> dst :: 0xff :: c |
let ins_tag i c = match i with | SetTag ( dst , src ) -> dst :: src :: c | EraseTag dst -> dst :: 0xff :: c |
let do_emit_code c = let r = Table . size code in List . iter emit_int c ; emit_int 0xff ; r |
let memory = Hashtbl . create 101 |
let mem_emit_code c = try Hashtbl . find memory c with | Not_found -> let r = do_emit_code c in Hashtbl . add memory c r ; r |
let _ = mem_emit_code [ ] |
let emit_tag_code c = mem_emit_code ( List . fold_right ins_tag c [ ] ) |
let most_frequent_elt v = let frequencies = Hashtbl . create 17 in let max_freq = ref 0 in let most_freq = ref ( v . ( 0 ) ) in for i = 0 to Array . length v - 1 do let e = v . ( i ) in let r = try Hashtbl . find frequencies e with Not_found -> let r = ref 1 in Hashtbl . add freq... |
let non_default_elements def v = let rec nondef i = if i >= Array . length v then [ ] else begin let e = v . ( i ) in if e = def then nondef ( i + 1 ) else ( i , e ) :: nondef ( i + 1 ) end in nondef 0 |
type t_compact = { mutable c_trans : int array ; mutable c_check : int array ; mutable c_last_used : int ; } |
let create_compact ( ) = { c_trans = Array . make 1024 0 ; c_check = Array . make 1024 ( - 1 ) ; c_last_used = 0 ; } |
let reset_compact c = c . c_trans <- Array . make 1024 0 ; c . c_check <- Array . make 1024 ( - 1 ) ; c . c_last_used <- 0 |
let trans = create_compact ( ) |
let grow_compact c = let old_trans = c . c_trans and old_check = c . c_check in let n = Array . length old_trans in c . c_trans <- Array . make ( 2 * n ) 0 ; Array . blit old_trans 0 c . c_trans 0 c . c_last_used ; c . c_check <- Array . make ( 2 * n ) ( - 1 ) ; Arra... |
let do_pack state_num orig compact = let default = most_frequent_elt orig in let nondef = non_default_elements default orig in let rec pack_from b = while b + 257 > Array . length compact . c_trans do grow_compact compact done ; let rec try_pack = function [ ] -> b | ( pos , _v ) :: rem -> ... |
let pack_moves state_num move_t = let move_v = Array . make 257 0 and move_m = Array . make 257 0 in for i = 0 to 256 do let act , c = move_t . ( i ) in move_v . ( i ) <- ( match act with Backtrack -> - 1 | Goto n -> n ) ; move_m . ( i ) <- emit_mem_code c done ; let pk... |
type lex_tables = { tbl_base : int array ; tbl_backtrk : int array ; tbl_default : int array ; tbl_trans : int array ; tbl_check : int array ; tbl_base_code : int array ; tbl_backtrk_code : int array ; tbl_default_code : int array ; tbl_trans_code : int array ; tbl_check_code : int array ... |
let compact_tables state_v = let n = Array . length state_v in let base = Array . make n 0 and backtrk = Array . make n ( - 1 ) and default = Array . make n 0 and base_code = Array . make n 0 and backtrk_code = Array . make n 0 and default_code = Array . make n 0 in for i = 0 to n - ... |
let debug = ref false |
let random_write_discard_compact nr_clusters stop_after = let open Lwt . Infix in let cluster_bits = 16 in let cluster_size = 1 lsl cluster_bits in let size = Int64 . ( mul nr_clusters ( of_int cluster_size ) ) in let path = Filename . concat test_dir ( Int64 . to_string size ) ^ " . com... |
let _ = Logs . set_reporter ( Logs_fmt . reporter ( ) ) ; let clusters = ref 128 in let stop_after = ref 1024 in Arg . parse [ " - clusters " , Arg . Set_int clusters , Printf . sprintf " Total number of clusters ( default % d ) " ! clusters ; " - stop - after " , ... |
* ( b ) Otherwise , we have an approximant a1 ' , and . . . * ( i ) If b1 and b2 are of types that may contain names that require * unification , compare b1 and b2 . * ( I ) If they are equivalent , the approximant is F ( a1 ' , b2 ) . * ( II ) Otherwise , we have an a... |
module Comparison = struct type ' a t = | Equivalent | Different of { approximant : ' a } let map ~ f = function | Equivalent -> Equivalent | Different { approximant } -> Different { approximant = f approximant } let is_equivalent = function Equivalent -> true | Different _ -> false let... |
let log f e1 e2 thunk = if debugging then begin if debugging_verbose then begin Format . eprintf " [ @< v [ >@< hv > COMPARING ; @< 1 2 >% a ; @< 1 0 > TO ; @< 1 2 >% a ] , ; @@---@< 0 2 " > f e1 f e2 ; let ans = thunk ( ) in Format . eprintf " % a ] , " @@ (... |
let log_rel f e1 rel e2 = if debugging && debugging_verbose then Format . eprintf " [ @< hv >% a ; @< 1 2 >% s ; @< 1 0 >% a ] , " @@ f e1 rel f e2 |
let log_eq p f e1 e2 = if debugging && debugging_verbose then let rel = if p e1 e2 then " " = else " " /= in log_rel f e1 rel e2 |
let log_comp c f e1 e2 = if debugging && debugging_verbose then let rel = match c e1 e2 with n when n < 0 -> " " < | 0 -> " " = | _ -> " " > in log_rel f e1 rel e2 |
module Env = struct type t = { mutable symbols : Symbol . t Symbol . Map . t ; mutable code_ids : Code_id . t Code_id . Map . t ; mutable function_slots : Function_slot . t Function_slot . Map . t ; mutable function_slots_rev : Function_slot . t Function_slot . Map . t ; mutable ... |
let subst_function_slot ( env : Env . t ) function_slot = Env . find_function_slot env function_slot |> Option . value ~ default : function_slot |
let subst_code_id ( env : Env . t ) code_id = Env . find_code_id env code_id |> Option . value ~ default : code_id |
let subst_symbol ( env : Env . t ) symbol = Env . find_symbol env symbol |> Option . value ~ default : symbol |
let subst_value_slot ( env : Env . t ) var = Env . find_value_slot env var |> Option . value ~ default : var |
let subst_name env n = Name . pattern_match n ~ var ( : fun _ -> n ) ~ symbol ( : fun s -> Name . symbol ( subst_symbol env s ) ) |
let subst_simple env s = Simple . pattern_match s ~ const ( : fun _ -> s ) ~ name ( : fun n ~ coercion : _ -> Simple . name ( subst_name env n ) ) |
let subst_unary_primitive env ( p : Flambda_primitive . unary_primitive ) : Flambda_primitive . unary_primitive = match p with | Project_function_slot { move_from ; move_to } -> let move_from = subst_function_slot env move_from in let move_to = subst_function_slot env move_to in Project_function_sl... |
let subst_primitive env ( p : Flambda_primitive . t ) : Flambda_primitive . t = match p with | Unary ( unary_primitive , arg ) -> Unary ( subst_unary_primitive env unary_primitive , subst_simple env arg ) | _ -> p |
let subst_func_decl env code_id = subst_code_id env code_id |
let subst_func_decls env decls = Function_declarations . funs_in_order decls |> Function_slot . Lmap . bindings |> List . map ( fun ( function_slot , func_decl ) -> let function_slot = subst_function_slot env function_slot in let func_decl = subst_func_decl env func_decl in function_slot , func_... |
let subst_set_of_closures env set = let decls = subst_func_decls env ( Set_of_closures . function_decls set ) in let value_slots = Set_of_closures . value_slots set |> Value_slot . Map . bindings |> List . map ( fun ( var , simple ) -> subst_value_slot env var , subst_simple env simple ) ... |
let subst_rec_info_expr _env ri = ri |
let subst_field env ( field : Field_of_static_block . t ) = match field with | Symbol symbol -> Field_of_static_block . Symbol ( subst_symbol env symbol ) | Tagged_immediate _ | Dynamically_computed _ -> field |
let subst_call_kind env ( call_kind : Call_kind . t ) : Call_kind . t = match call_kind with | Function { function_call = Direct { code_id ; return_arity } ; _ } -> let code_id = subst_code_id env code_id in Call_kind . direct_function_call code_id ~ return_arity Heap | _ -> call_kind |
let rec subst_expr env e = match Expr . descr e with | Let let_expr -> subst_let_expr env let_expr | Let_cont let_cont -> subst_let_cont env let_cont | Apply apply -> subst_apply env apply | Apply_cont apply_cont -> subst_apply_cont env apply_cont |> Expr . create_apply_cont | Switch switch -> subst_swi... |
module Comparator = struct type ' a t = Env . t -> ' a -> ' a -> ' a Comparison . t let of_predicate ( ~ f : ' a -> ' a -> bool ) ( ? subst : ( Env . t -> ' a -> ' a ) option ) : ' a t = fun env a1 a2 -> if f a1 a2 then Equivalent else let approximant = match subst w... |
let pairs ( ~ f1 : ' a Comparator . t ) ( ~ f2 : ' b Comparator . t ) ( ? subst2 : ( Env . t -> ' b -> ' b ) option ) : ( ' a * ' b ) Comparator . t = fun env ( a1 , b1 ) ( a2 , b2 ) -> match f1 env a1 a2 with | Equivalent -> f2 env b1 b2 |> Comparison ... |
let triples ( ~ f1 : ' a Comparator . t ) ( ~ f2 : ' b Comparator . t ) ( ~ f3 : ' c Comparator . t ) ( ? subst2 : ( Env . t -> ' b -> ' b ) option ) ( ? subst3 : ( Env . t -> ' c -> ' c ) option ) : ( ' a * ' b * ' c ) Comparator . t = f... |
let rec lists ( ~ f : ' a Comparator . t ) ( ~ subst : Env . t -> ' a -> ' a ) ~ subst_snd : ' a list Comparator . t = fun env list1 list2 -> match list1 , list2 with | a1 :: list1 , a2 :: list2 -> let subst2 = if subst_snd then Some ( fun env -> List . map ( subst env ) ... |
let options ~ f ~ subst env o1 o2 = match o1 , o2 with | Some a1 , Some a2 -> f env a1 a2 |> Comparison . map ~ f ( : fun a1 ' -> Some a1 ' ) | None , None -> Comparison . Equivalent | Some a1 , None -> Comparison . Different { approximant = Some ( subst env a1 ) } | None , ... |
let symbols env symbol1 symbol2 : Symbol . t Comparison . t = log Symbol . print symbol1 symbol2 ( fun ( ) -> let symbol1 = subst_symbol env symbol1 in if Symbol . equal symbol1 symbol2 then Equivalent else Different { approximant = symbol1 } ) |
let code_ids env code_id1 code_id2 : Code_id . t Comparison . t = let code_id1 = subst_code_id env code_id1 in if Code_id . equal code_id1 code_id2 then Equivalent else Different { approximant = code_id1 } |
let function_slots env function_slot1 function_slot2 : Function_slot . t Comparison . t = match Env . find_function_slot env function_slot1 with | Some function_slot -> if Function_slot . equal function_slot function_slot2 then Equivalent else Different { approximant = function_slot } | None -> ( m... |
let value_slots env value_slot1 value_slot2 : Value_slot . t Comparison . t = match Env . find_value_slot env value_slot1 with | Some value_slot -> if Value_slot . equal value_slot value_slot2 then Equivalent else Different { approximant = value_slot } | None -> ( match Env . find_value_slot_rev ... |
let names env name1 name2 : Name . t Comparison . t = log Name . print name1 name2 ( fun ( ) -> Name . pattern_match name1 ~ var ( : fun var1 -> Name . pattern_match name2 ~ var ( : fun var2 : Name . t Comparison . t -> if Variable . equal var1 var2 then Equivalent else Different { ... |
let simple_exprs env simple1 simple2 : Simple . t Comparison . t = Simple . pattern_match simple1 ~ name ( : fun name1 ~ coercion : _ -> Simple . pattern_match simple2 ~ name ( : fun name2 ~ coercion : _ -> names env name1 name2 |> Comparison . map ~ f : Simple . name ) ~ const ( ... |
let print_list f ppf l = let pp_sep ppf ( ) = Format . fprintf ppf " ; ; @< 1 2 " > in Format . fprintf ppf " [ @< hv [ >@ % a @ ] ] " @ ( Format . pp_print_list ~ pp_sep f ) l |
let simple_lists env list1 list2 : Simple . t list Comparison . t = log ( print_list Simple . print ) list1 list2 ( fun ( ) -> lists ~ f : simple_exprs ~ subst : subst_simple ~ subst_snd : true env list1 list2 ) |
let unary_prim_ops env ( prim_op1 : Flambda_primitive . unary_primitive ) ( prim_op2 : Flambda_primitive . unary_primitive ) : Flambda_primitive . unary_primitive Comparison . t = match prim_op1 , prim_op2 with | ( Project_function_slot { move_from = move_from1 ; move_to = move_to1 } , ... |
let primitives env prim1 prim2 : Flambda_primitive . t Comparison . t = match ( prim1 : Flambda_primitive . t ) , ( prim2 : Flambda_primitive . t ) with | Unary ( prim_op1 , arg1 ) , Unary ( prim_op2 , arg2 ) -> pairs ~ f1 : unary_prim_ops ~ f2 : simple_exprs ~ subst2 : subst... |
let function_decls env code_id1 code_id2 : unit Comparison . t = if code_ids env code_id1 code_id2 |> Comparison . is_equivalent then Equivalent else Different { approximant = ( ) } |
let iter2_merged l1 l2 ~ compare ~ f = let l1 = List . sort compare l1 in let l2 = List . sort compare l2 in let rec go l1 l2 = match l1 , l2 with | [ ] , [ ] -> ( ) | a1 :: l1 , [ ] -> f ( Some a1 ) None ; go l1 [ ] | [ ] , a2 :: l2 -> f None ( Some a2 ) ; ... |
let sets_of_closures env set1 set2 : Set_of_closures . t Comparison . t = let value_slots_by_value set = Value_slot . Map . bindings ( Set_of_closures . value_slots set ) |> List . map ( fun ( var , value ) -> subst_simple env value , var ) in let ok = ref true in let ( ) = let co... |
let rec_info_exprs _env rec_info_expr1 rec_info_expr2 : Rec_info_expr . t Comparison . t = if Rec_info_expr . equal rec_info_expr1 rec_info_expr2 then Equivalent else Different { approximant = rec_info_expr1 } |
let named_exprs env named1 named2 : Named . t Comparison . t = match ( named1 : Named . t ) , ( named2 : Named . t ) with | Simple simple1 , Simple simple2 -> simple_exprs env simple1 simple2 |> Comparison . map ~ f : Named . create_simple | Prim ( prim1 , dbg1 ) , Prim ( pri... |
let patterns env ( pattern1 : Bound_static . Pattern . t ) ( pattern2 : Bound_static . Pattern . t ) : Bound_static . Pattern . t Comparison . t = match pattern1 , pattern2 with | Code code_id1 , Code code_id2 -> Env . add_code_id env code_id1 code_id2 ; Equivalent | Block_like symb... |
let bound_static env bound_static1 bound_static2 : Bound_static . t Comparison . t = lists ~ f : patterns ~ subst : subst_pattern ~ subst_snd : false env ( bound_static1 |> Bound_static . to_list ) ( bound_static2 |> Bound_static . to_list ) |> Comparison . map ~ f : Bound_static . crea... |
let fields env ( field1 : Field_of_static_block . t ) ( field2 : Field_of_static_block . t ) : Field_of_static_block . t Comparison . t = match field1 , field2 with | Symbol symbol1 , Symbol symbol2 -> symbols env symbol1 symbol2 |> Comparison . map ~ f ( : fun symbol1 ' -> Field_of_... |
let blocks env block1 block2 = triples ~ f1 ( : Comparator . of_predicate ~ f : Tag . Scannable . equal ) ~ f2 ( : Comparator . of_ordering ~ f : Mutability . compare ) ~ f3 ( : lists ~ f : fields ~ subst : subst_field ~ subst_snd : true ) ~ subst2 ( : fun _ mut -> mut ) ... |
let method_kinds _env ( method_kind1 : Call_kind . method_kind ) ( method_kind2 : Call_kind . method_kind ) : Call_kind . method_kind Comparison . t = match method_kind1 , method_kind2 with | Self , Self | Public , Public | Cached , Cached -> Equivalent | _ , _ -> Different { ap... |
let call_kinds env ( call_kind1 : Call_kind . t ) ( call_kind2 : Call_kind . t ) : Call_kind . t Comparison . t = match call_kind1 , call_kind2 with | ( Function { function_call = Direct { code_id = code_id1 ; return_arity = return_arity1 } ; _ } , Function { function_call ... |
let inlining_states_equal is1 is2 : bool = Inlining_state . depth is1 = Inlining_state . depth is2 |
let apply_exprs env apply1 apply2 : Expr . t Comparison . t = let atomic_things_equal = Apply . Result_continuation . equal ( Apply . continuation apply1 ) ( Apply . continuation apply2 ) && Exn_continuation . equal ( Apply . exn_continuation apply1 ) ( Apply . exn_continuation apply... |
let apply_cont_exprs env apply_cont1 apply_cont2 : Apply_cont . t Comparison . t = let cont1 = Apply_cont . continuation apply_cont1 in let cont2 = Apply_cont . continuation apply_cont2 in log_eq Continuation . equal Continuation . print cont1 cont2 ; log_comp ( Option . compare Trap_action . co... |
let switch_exprs env switch1 switch2 : Expr . t Comparison . t = let compare_arms env arms1 arms2 = lists ~ f : ( pairs ~ f1 ( : Comparator . of_predicate ~ f : Targetint_31_63 . equal ) ~ f2 : apply_cont_exprs ~ subst2 : subst_apply_cont ) ~ subst ( : fun env ( target_imm , apply_c... |
let rec exprs env e1 e2 : Expr . t Comparison . t = log Expr . print e1 e2 ( fun ( ) -> match Expr . descr e1 , Expr . descr e2 with | Let let_expr1 , Let let_expr2 -> let_exprs env let_expr1 let_expr2 | Let_cont let_cont1 , Let_cont let_cont2 -> let_cont_exprs env let_cont1 let_cont2 | Ap... |
let flambda_units u1 u2 = let ret_cont = Continuation . create ~ sort : Toplevel_return ( ) in let exn_cont = Continuation . create ( ) in let mk_perm u = let perm = Renaming . empty in let perm = Renaming . add_fresh_continuation perm ( Flambda_unit . return_continuation u ) ~ guaranteed... |
let output_prefix name = let oname = match ! output_name with | None -> name | Some n -> if ! compile_only then ( output_name := None ; n ) else name in Filename . remove_extension oname |
let print_version_and_library compiler = Printf . printf " The OCaml % s , version " compiler ; print_string Config . version ; print_newline ( ) ; print_string " Standard library directory : " ; print_string Config . standard_library ; print_newline ( ) ; raise ( Exit_with_stat... |
let print_version_string ( ) = print_string Config . version ; print_newline ( ) ; raise ( Exit_with_status 0 ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.