text stringlengths 0 601k |
|---|
module Foo = struct let x = 42 end |
module type MY_MODULE_TYPE = sig val x : int end |
let f x y = x + y |
type my_record = { foo : int ; bar : string ; } object inherit cl val mutable tutu = " tutu " val toto = 1 val titi = " titi " method toto = tutu ^ " " ! method m ( f : float ) = 1 end object val mutable x : int method m : int -> int end |
module Foo = struct let x = 42 end |
module type MY_MODULE_TYPE = sig val x : int end |
let number num = Sexp ( Number num ) ; ; |
let symbol sym = Sexp ( Symbol sym ) ; ; |
let string_ str = Sexp ( String str ) ; ; |
let bool_ bl = Sexp ( Bool bl ) ; ; |
let list_ lst = Sexp ( List lst ) ; ; |
let dotted_list lst last = Sexp ( DottedList ( lst , last ) ) ; ; |
let prim_func name func = Func ( PrimFunc ( name , func ) ) ; ; |
let user_func func = Func ( UserFunc func ) ; ; |
let input_port name lb channel = Port ( InputPort ( name , lb , channel ) ) ; ; |
let output_port name channel = Port ( OutputPort ( name , channel ) ) ; ; |
let lisp_error error = raise ( Lisp_error error ) ; ; |
let arg_count_mismatch expected got = lisp_error ( ArgCountMismatch { arg_count_expected = expected ; arg_count_got = got } ) ; ; |
let arg_type_mismatch expected got = lisp_error ( ArgTypeMismatch { arg_type_expected = expected ; arg_type_got = got } ) ; ; |
let not_applicable value = lisp_error ( NotApplicable value ) ; ; |
let unbound_var var = lisp_error ( UnboundVar var ) ; ; |
let closed_chan chan = lisp_error ( ClosedChan chan ) ; ; |
let unpack_sexp value = match value with | Sexp sexp -> sexp | _ -> arg_type_mismatch " sexp " value ; ; |
let unpack_num value = match unpack_sexp value with | Number num -> num | _ -> arg_type_mismatch " number " value ; ; |
let unpack_sym value = match unpack_sexp value with | Symbol sym -> sym | _ -> arg_type_mismatch " symbol " value ; ; |
let unpack_str value = match unpack_sexp value with | String str -> str | _ -> arg_type_mismatch " string " value ; ; |
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 . print ) ) by_scope ( EP . Map . print Simple . print ) combined |
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 = Scope . Map . add scope level t... |
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 { bound_to : Simple . t } let bound_to t... |
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 ~ coercion : _ -> Name . Set . ... |
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 , extra_bindings , extra_equations , a... |
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_cse extra_param... |
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_between_fork_and_use = ... |
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 frequencies e r ; r in incr r ; if ! r > ! m... |
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 ) ; Array . blit old_check 0 c . c_check 0 c . c_last_used |
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 -> if compact . c_check . ( b + ... |
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_trans = do_pack state_num move_v trans and pk_mov... |
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 ; tbl_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 - 1 do match state_v . ( i ) with | Pe... |
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 ) ^ " . compact " in let t = truncate path ... |
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 " , Arg . Set_int stop_after , Printf . sprintf " Number of... |
* ( 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 approximant b1 ' , and the whole * approximant is F ... |
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 approximant t ~ default = match ... |
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 ] , " @@ ( Comparison . print f ) ans ; ans end else let ans : _ Compar... |
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 value_slots : Value_slot . t Value_slot ... |
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_slot { move_from ; move... |
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_decl ) |> Function_slot ... |
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 ) |> Value_slot . Map . of_list i... |
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_switch env switch |... |
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 with Some subst -> subst env a1 | None -> a1 in Differ... |
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 . map ~ f ( : fun b1 ' -> a2 , b1 ' ) | Different { approximant = a... |
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 = fun env ( a1 , b1 , c1 ) ( a2 , b2 , c2 ) -> let subst23 = match subst2 , subst3 wi... |
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 ) ) else None in pairs ~ f1 : f ~ f2 ( : lists ~ f... |
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 , Some _ -> Comparison . Different { approximan... |
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 -> ( match Env . find_funct... |
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 env value_slot2 with | ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.