text
stringlengths
0
601k
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 { approximant = name1 } ) ~ symbol ( : ...
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 ( : fun _ -> Comparison . Different { app...
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 } , Project_function_slot { move_from...
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_simple env ( prim_op1 , arg1 ) ( prim_op2 ,...
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 ) ; go [ ] l2 | a1 :: l1 , a2 :: l2 -> begin match compare a1 a2 w...
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 compare ( value1 , _var1 ) ( value2 , _va...
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 ( prim2 , _ ) -> primitives env prim1 prim2 |> Co...
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 symbol1 , Block_like symbol2 -> Env . add...
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 . create
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_static_block . Symbol symbol1 ' ) | ...
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 ) ~ subst3 ( : fun env -> List . map ( subst_field...
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 { approximant = method_kind1 }
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 = Direct { code_id = code_id2 ; return_arity =...
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 apply2 ) && Inlined_attribute . equal ( A...
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 . compare ) ( Format . pp_pr...
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_cont ) -> target_imm , subst_apply_con...
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 | Apply apply1 , Apply apply2 -> a...
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_fresh : ret_cont in let perm =...
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_status 0 )
let print_version_string ( ) = print_string Config . version ; print_newline ( ) ; raise ( Exit_with_status 0 )
let print_standard_library ( ) = print_string Config . standard_library ; print_newline ( ) ; raise ( Exit_with_status 0 )
let fatal err = prerr_endline err ; raise ( Exit_with_status 2 )
let extract_output = function | Some s -> s | None -> fatal " Please specify the name of the output file , using option - o "
let default_output = function | Some s -> s | None -> Config . default_executable_name
let first_include_dirs = ref [ ]
let last_include_dirs = ref [ ]
let first_ccopts = ref [ ]
let last_ccopts = ref [ ]
let first_ppx = ref [ ]
let last_ppx = ref [ ]
let first_objfiles = ref [ ]
let last_objfiles = ref [ ]
let stop_early = ref false
let is_unit_name name = try if name = " " then raise Exit ; begin match name . [ 0 ] with | ' A ' . . ' Z ' -> ( ) | _ -> raise Exit ; end ; for i = 1 to String . length name - 1 do match name . [ i ] with | ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' | ' ' ' \ -> ( ) | _ -> raise Exit ; done ; true wit...
let check_unit_name filename name = if not ( is_unit_name name ) then Location . prerr_warning ( Location . in_file filename ) ( Warnings . Bad_module_name name ) ; ;
let module_of_filename inputfile outputprefix = let basename = Filename . basename outputprefix in let name = try let pos = String . index basename ' . ' in String . sub basename 0 pos with Not_found -> basename in let name = String . capitalize_ascii name in check_unit_name inputfile name ; name ; ;
type readenv_position = Before_args | Before_compile of filename | Before_link
let print_error ppf msg = Location . print_warning Location . none ppf ( Warnings . Bad_env_variable ( " OCAMLPARAM " , msg ) )
let parse_args s = let args = let len = String . length s in if len = 0 then [ ] else match s . [ 0 ] with | ( ' ' : | ' ' | | ' ; ' | ' ' | ' , ' ) as c -> List . tl ( String . split_on_char c s ) | _ -> String . split_on_char ' , ' s in let rec iter is_after args before after = match args with [ ] -> if not is_after ...
let setter ppf f name options s = try let bool = match s with | " 0 " -> false | " 1 " -> true | _ -> raise Not_found in List . iter ( fun b -> b := f bool ) options with Not_found -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name
let int_setter ppf name option s = try option := int_of_string s with _ -> Printf . ksprintf ( print_error ppf ) " non - integer parameter % s for % S " s name
let int_option_setter ppf name option s = try option := Some ( int_of_string s ) with _ -> Printf . ksprintf ( print_error ppf ) " non - integer parameter % s for % S " s name
let check_bool ppf name s = match s with | " 0 " -> false | " 1 " -> true | _ -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name ; false
let check_int ppf name s = match int_of_string s with | i -> Some i | exception _ -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name ; None
let decode_compiler_pass ppf v ~ name ~ filter = let module P = Clflags . Compiler_pass in let passes = P . available_pass_names ~ filter ~ native :! native_code in begin match List . find_opt ( String . equal v ) passes with | None -> Printf . ksprintf ( print_error ppf ) " bad value % s for option " \% s " \ ( expect...
let set_compiler_pass ppf ~ name v flag ~ filter = match decode_compiler_pass ppf v ~ name ~ filter with | None -> ( ) | Some pass -> match ! flag with | None -> flag := Some pass | Some p -> if not ( p = pass ) then begin Printf . ksprintf ( print_error ppf ) " Please specify at most one % s < pass . " > name end
let can_discard = ref [ ]
let warnings_for_discarded_params = ref false
let extra_params = ref None
let set_extra_params params = extra_params := params
let read_one_param ppf position name v = let set name options s = setter ppf ( fun b -> b ) name options s in let clear name options s = setter ppf ( fun b -> not b ) name options s in let handled = match ! extra_params with | Some h -> h ppf position name v | None -> false in if not handled then match name with | " g ...
let read_OCAMLPARAM ppf position = try let s = Sys . getenv " OCAMLPARAM " in if s <> " " then let ( before , after ) = try parse_args s with SyntaxError s -> print_error ppf s ; [ ] , [ ] in List . iter ( fun ( name , v ) -> read_one_param ppf position name v ) ( match position with Before_args -> before | Before_comp...
type pattern = | Filename of string | Any
type file_option = { pattern : pattern ; name : string ; value : string ; }
let scan_line ic = Scanf . bscanf ic " [ % 0 - 9a - zA - Z_ . ] * : [ % a - zA - Z_ ] - = % s " ( fun pattern name value -> let pattern = match pattern with | " " * -> Any | _ -> Filename pattern in { pattern ; name ; value } )
let load_config ppf filename = match open_in_bin filename with | exception e -> Location . errorf ~ loc ( : Location . in_file filename ) " Cannot open file % s " ( Printexc . to_string e ) |> Location . print_report ppf ; raise Exit | ic -> let sic = Scanf . Scanning . from_channel ic in let rec read line_number line_...
let matching_filename filename { pattern } = match pattern with | Any -> true | Filename pattern -> let filename = String . lowercase_ascii filename in let pattern = String . lowercase_ascii pattern in filename = pattern
let apply_config_file ppf position = let config_file = Filename . concat Config . standard_library " ocaml_compiler_internal_params " in let config = if Sys . file_exists config_file then load_config ppf config_file else [ ] in let config = match position with | Before_compile filename -> List . filter ( matching_filen...
let readenv ppf position = last_include_dirs := [ ] ; last_ccopts := [ ] ; last_ppx := [ ] ; last_objfiles := [ ] ; apply_config_file ppf position ; read_OCAMLPARAM ppf position ; all_ccopts := ! last_ccopts @ ! first_ccopts ; all_ppx := ! last_ppx @ ! first_ppx
let get_objfiles ~ with_ocamlparam = if with_ocamlparam then List . rev ( ! last_objfiles @ ! objfiles @ ! first_objfiles ) else List . rev ! objfiles
type deferred_action = | ProcessImplementation of string | ProcessInterface of string | ProcessCFile of string | ProcessOtherFile of string | ProcessObjects of string list | ProcessDLLs of string list
let c_object_of_filename name = Filename . chop_suffix ( Filename . basename name ) " . c " ^ Config . ext_obj
let process_action ( ppf , implementation , interface , ocaml_mod_ext , ocaml_lib_ext ) action ~ keep_symbol_tables = let impl ~ start_from name = readenv ppf ( Before_compile name ) ; let opref = output_prefix name in implementation ~ start_from ~ source_file : name ~ output_prefix : opref ~ keep_symbol_tables ; objfi...
let action_of_file name = if Filename . check_suffix name " . ml " || Filename . check_suffix name " . mlt " then ProcessImplementation name else if Filename . check_suffix name ! Config . interface_suffix then ProcessInterface name else if Filename . check_suffix name " . c " then ProcessCFile name else ProcessOtherFi...
let deferred_actions = ref [ ]
let defer action = deferred_actions := action :: ! deferred_actions
let anonymous filename = defer ( action_of_file filename )
let impl filename = defer ( ProcessImplementation filename )
let intf filename = defer ( ProcessInterface filename )
let process_deferred_actions env = let final_output_name = ! output_name in if not ! compile_only then output_name := None ; begin match final_output_name with | None -> ( ) | Some output_name -> if ! compile_only then begin if List . filter ( function | ProcessCFile name -> c_object_of_filename name <> output_name | _...
type t = { id : Ident . t ; linkage_name : Linkage_name . t ; hash : int ; }
let string_for_printing t = Ident . name t . id type nonrec t = t let compare v1 v2 = if v1 == v2 then 0 else let c = compare v1 . hash v2 . hash in if c = 0 then let v1_id = Ident . name v1 . id in let v2_id = Ident . name v2 . id in let c = String . compare v1_id v2_id in if c = 0 then Linkage_name . compare v1 . lin...
let create ( id : Ident . t ) linkage_name = if not ( Ident . persistent id ) then begin Misc . fatal_error " Compilation_unit . create with non - persistent Ident . t " end ; { id ; linkage_name ; hash = Hashtbl . hash ( Ident . name id ) ; }
let get_persistent_ident cu = cu . id
let get_linkage_name cu = cu . linkage_name
let current = ref None
let is_current arg = match ! current with | None -> Misc . fatal_error " Current compilation unit is not set " ! | Some cur -> equal cur arg
let set_current t = current := Some t
let get_current ( ) = ! current
let get_current_exn ( ) = match ! current with | Some current -> current | None -> Misc . fatal_error " Compilation_unit . get_current_exn "
let get_current_id_exn ( ) = get_persistent_ident ( get_current_exn ( ) )
let with_info = Compile_common . with_info ~ native : false ~ tool_name
let interface ~ source_file ~ output_prefix = with_info ~ source_file ~ output_prefix ~ dump_ext " : cmi " @@ fun info -> Compile_common . interface ~ hook_parse_tree ( : fun _ -> ( ) ) ~ hook_typed_tree ( : fun _ -> ( ) ) info
let to_bytecode i ( typedtree , coercion ) = ( typedtree , coercion ) |> Profile . ( record transl ) ( Translmod . transl_implementation i . module_name ) |> Profile . ( record ~ accumulate : true generate ) ( fun { Lambda . code = lambda ; required_globals } -> lambda |> print_if i . ppf_dump Clflags . dump_rawlambda ...
let emit_bytecode i ( bytecode , required_globals ) = let cmofile = cmo i in let oc = open_out_bin cmofile in Misc . try_finally ~ always ( : fun ( ) -> close_out oc ) ~ exceptionally ( : fun ( ) -> Misc . remove_file cmofile ) ( fun ( ) -> bytecode |> Profile . ( record ~ accumulate : true generate ) ( Emitcode . to_f...
let implementation ~ start_from ~ source_file ~ output_prefix ~ keep_symbol_tables : _ = let backend info typed = let bytecode = to_bytecode info typed in emit_bytecode info bytecode in with_info ~ source_file ~ output_prefix ~ dump_ext " : cmo " @@ fun info -> match ( start_from : Clflags . Compiler_pass . t ) with | ...
type error = Not_a_unit_info of string | Corrupted_unit_info of string | Illegal_renaming of string * string * string
let global_infos_table = ( Hashtbl . create 17 : ( string , unit_infos option ) Hashtbl . t )
let export_infos_table = ( Hashtbl . create 10 : ( string , Export_info . t ) Hashtbl . t )
let imported_sets_of_closures_table = ( Set_of_closures_id . Tbl . create 10 : Simple_value_approx . function_declarations option Set_of_closures_id . Tbl . t )
module CstMap = Map . Make ( struct type t = Clambda . ustructured_constant let compare = Clambda . compare_structured_constants end )
type structured_constants = { strcst_shared : string CstMap . t ; strcst_all : Clambda . ustructured_constant SymMap . t ; }
let structured_constants_empty = { strcst_shared = CstMap . empty ; strcst_all = SymMap . empty ; }
let structured_constants = ref structured_constants_empty