text
stringlengths
12
786k
let mk_dflexpect f = " - dflexpect " , Arg . Unit f , " Like - dflambda but outputs a . flt file \ n \ \ whose basename matches that of the input . ml file ( Flambda 2 only ) " ; ;
let mk_dslot_offsets f = " - dslot - offsets " , Arg . Unit f , " Dump closure offsets ( Flambda 2 only ) " ; ;
let mk_dfreshen f = " - dfreshen " , Arg . Unit f , " Freshen bound names when printing ( Flambda 2 only ) " ; ;
let mk_restrict_to_upstream_dwarf f = " - gupstream - dwarf " , Arg . Unit f , " Only emit the same DWARF information as the upstream compiler "
let mk_no_restrict_to_upstream_dwarf f = " - gno - upstream - dwarf " , Arg . Unit f , " Emit potentially more DWARF information than the upstream compiler "
module type Flambda_backend_options = sig val ocamlcfg : unit -> unit val no_ocamlcfg : unit -> unit val dump_inlining_paths : unit -> unit val dcfg : unit -> unit val dcfg_invariants : unit -> unit val dcfg_equivalence_check : unit -> unit val reorder_blocks_random : int -> unit val heap_reduction_thres...
module Make_flambda_backend_options ( F : Flambda_backend_options ) = struct let list2 = [ mk_dump_inlining_paths F . dump_inlining_paths ; mk_ocamlcfg F . ocamlcfg ; mk_no_ocamlcfg F . no_ocamlcfg ; mk_dcfg F . dcfg ; mk_dcfg_invariants F . dcfg_invariants ; mk_dcfg_equivalence_check F . ...
module Flambda_backend_options_impl = struct let set r ( ) = r := Flambda_backend_flags . Set true let clear r ( ) = r := Flambda_backend_flags . Set false let set ' r ( ) = r := true let clear ' r ( ) = r := false let ocamlcfg = set ' Flambda_backend_flags . use_ocamlcfg let no_oc...
module type Debugging_options = sig val _restrict_to_upstream_dwarf : unit -> unit val _no_restrict_to_upstream_dwarf : unit -> unit end
module Make_debugging_options ( F : Debugging_options ) = struct let list3 = [ mk_restrict_to_upstream_dwarf F . _restrict_to_upstream_dwarf ; mk_no_restrict_to_upstream_dwarf F . _no_restrict_to_upstream_dwarf ] end
module Debugging_options_impl = struct let _restrict_to_upstream_dwarf ( ) = Debugging . restrict_to_upstream_dwarf := true let _no_restrict_to_upstream_dwarf ( ) = Debugging . restrict_to_upstream_dwarf := false end
module Extra_params = struct let read_param ppf _position name v = let set option = let b = Compenv . check_bool ppf name v in option := Flambda_backend_flags . Set b ; true in let _clear option = let b = Compenv . check_bool ppf name v in option := Flambda_backend_flags . Set ( not b ) ; fals...
module type Optcomp_options = sig include Main_args . Optcomp_options include Flambda_backend_options include Debugging_options end
module type Opttop_options = sig include Main_args . Opttop_options include Flambda_backend_options include Debugging_options end
module Make_optcomp_options ( F : Optcomp_options ) = struct include Make_debugging_options ( F ) include Make_flambda_backend_options ( F ) include Main_args . Make_optcomp_options ( F ) let list = list3 @ list2 @ list end
module Make_opttop_options ( F : Opttop_options ) = struct include Make_debugging_options ( F ) include Make_flambda_backend_options ( F ) include Main_args . Make_opttop_options ( F ) let list = list3 @ list2 @ list end
module Default = struct module Optmain = struct include Main_args . Default . Optmain include Flambda_backend_options_impl include Debugging_options_impl end module Opttopmain = struct include Main_args . Default . Opttopmain include Flambda_backend_options_impl include Debugging_options_impl end end
let use_ocamlcfg = ref false
let dump_cfg = ref false
let cfg_invariants = ref false
let cfg_equivalence_check = ref false
let reorder_blocks_random = ref None
let default_heap_reduction_threshold = 500_000_000 / ( Sys . word_size / 8 )
let heap_reduction_threshold = ref default_heap_reduction_threshold
type function_result_types = Never | Functors_only | All_functions
type opt_level = Oclassic | O2 | O3
type ' a or_default = Set of ' a | Default
let dump_inlining_paths = ref false
let opt_level = ref Default
let flags_by_opt_level ~ opt_level ~ default ~ oclassic ~ o2 ~ o3 = match opt_level with | Default -> default | Set Oclassic -> oclassic | Set O2 -> o2 | Set O3 -> o3
module Flambda2 = struct module Default = struct let classic_mode = false let join_points = false let unbox_along_intra_function_control_flow = true let backend_cse_at_toplevel = false let cse_depth = 2 let join_depth = 5 let function_result_types = Never let unicode = true end type flags = { classic_mod...
let set_oclassic ( ) = if Clflags . is_flambda2 ( ) then begin Flambda2 . Inlining . use_inlining_arguments_set Flambda2 . Inlining . oclassic_arguments ; opt_level := Set Oclassic end else begin Clflags . Opt_flag_handler . default . set_oclassic ( ) ; end
let set_o2 ( ) = if Clflags . is_flambda2 ( ) then begin Flambda2 . Inlining . use_inlining_arguments_set Flambda2 . Inlining . o2_arguments ; opt_level := Set O2 end else begin Clflags . Opt_flag_handler . default . set_o2 ( ) ; end
let set_o3 ( ) = if Clflags . is_flambda2 ( ) then begin Flambda2 . Inlining . use_inlining_arguments_set Flambda2 . Inlining . o3_arguments ; opt_level := Set O3 end else begin Clflags . Opt_flag_handler . default . set_o3 ( ) ; end
let opt_flag_handler : Clflags . Opt_flag_handler . t = { set_oclassic ; set_o2 ; set_o3 }
type loader = { get_global_info : Compilation_unit . t -> Flambda_cmx_format . t option ; mutable imported_names : Name . Set . t ; mutable imported_code : Exported_code . t ; mutable imported_units : TE . t option Compilation_unit . Map . t }
let rec load_cmx_file_contents loader comp_unit = match Compilation_unit . Map . find comp_unit loader . imported_units with | typing_env_or_none -> typing_env_or_none | exception Not_found -> ( match loader . get_global_info comp_unit with | None -> loader . imported_units <- Compilation_unit . M...
let load_symbol_approx loader symbol : Code_or_metadata . t Value_approximation . t = let comp_unit = Symbol . compilation_unit symbol in match load_cmx_file_contents loader comp_unit with | None -> Value_unknown | Some typing_env -> let find_code code_id = match Exported_code . find loader . imported...
let all_predefined_exception_symbols ~ symbol_for_global = Predef . all_predef_exns |> List . map ( fun ident -> symbol_for_global ? comp_unit ( : Some ( Compilation_unit . predefined_exception ( ) ) ) ident ) |> Symbol . Set . of_list
let predefined_exception_typing_env ~ symbol_for_global loader = let comp_unit = Compilation_unit . get_current_exn ( ) in Compilation_unit . set_current ( Compilation_unit . predefined_exception ( ) ) ; let resolver comp_unit = load_cmx_file_contents loader comp_unit in let get_imported_names (...
let create_loader ~ get_global_info ~ symbol_for_global = let loader = { get_global_info ; imported_names = Name . Set . empty ; imported_code = Exported_code . empty ; imported_units = Compilation_unit . Map . empty } in let predefined_exception_typing_env = predefined_exception_typing_env ...
let get_imported_names loader ( ) = loader . imported_names
let get_imported_code loader ( ) = loader . imported_code
let compute_reachable_names_and_code ~ module_symbol ~ free_names_of_name code = let rec fixpoint names_to_add names_already_added = if Name_occurrences . is_empty names_to_add then names_already_added else let names_already_added = Name_occurrences . union names_to_add names_already_added in let fold_code_id ...
let prepare_cmx ~ module_symbol create_typing_env ~ free_names_of_name ~ used_value_slots ~ canonicalise ~ exported_offsets all_code = let reachable_names = compute_reachable_names_and_code ~ module_symbol ~ free_names_of_name all_code in let all_code = all_code |> EC . remove_unused_value_slots_from_resul...
let prepare_cmx_file_contents ~ final_typing_env ~ module_symbol ~ used_value_slots ~ exported_offsets all_code = match final_typing_env with | None -> None | Some _ when Flambda_features . opaque ( ) -> None | Some final_typing_env -> let typing_env , canonicalise = TE . Pre_serializable . cre...
let prepare_cmx_from_approx ~ approxs ~ module_symbol ~ exported_offsets ~ used_value_slots all_code = if Flambda_features . opaque ( ) then None else let create_typing_env reachable_names = let approxs = Symbol . Map . filter ( fun sym _ -> Name_occurrences . mem_symbol reachable_names sym ) a...
type table_data = { symbols : ( Symbol . t * Symbol . exported ) list ; variables : ( Variable . t * Variable . exported ) list ; simples : ( Simple . t * Simple . exported ) list ; consts : ( Reg_width_const . t * Reg_width_const . exported ) list ; code_ids : ( Co...
type t0 = { original_compilation_unit : Compilation_unit . t ; final_typing_env : Flambda2_types . Typing_env . Serializable . t ; all_code : Exported_code . t ; exported_offsets : Exported_offsets . t ; used_value_slots : Value_slot . Set . t ; table_data : table_data }
type t = t0 list
let create ~ final_typing_env ~ all_code ~ exported_offsets ~ used_value_slots = let typing_env_exported_ids = Flambda2_types . Typing_env . Serializable . all_ids_for_export final_typing_env in let all_code_exported_ids = Exported_code . all_ids_for_export all_code in let exported_ids = Ids_for_export ...
module Make_importer ( S : sig type t type exported val import : exported -> t val map_compilation_unit : ( Compilation_unit . t -> Compilation_unit . t ) -> exported -> exported include Container_types . S with type t := t val import : ( S . t * S . exported ) list -> S . t S . Map ....
module Symbol_importer = Make_importer ( Symbol )
module Variable_importer = Make_importer ( Variable )
module Simple_importer = Make_importer ( Simple )
module Const_importer = Make_importer ( Reg_width_const )
module Code_id_importer = Make_importer ( Code_id )
module Continuation_importer = Make_importer ( Continuation )
let import_typing_env_and_code0 t = let symbols = Symbol_importer . import t . table_data . symbols in let variables = Variable_importer . import t . table_data . variables in let simples = Simple_importer . import t . table_data . simples in let consts = Const_importer . import t . table_dat...
let import_typing_env_and_code t = match t with | [ ] -> Misc . fatal_error " Flambda cmx info should never be empty " | [ t0 ] -> import_typing_env_and_code0 t0 | t0 :: rem -> List . fold_left ( fun ( typing_env , code ) t0 -> let typing_env0 , code0 = import_typing_env_and_code0 t0...
let exported_offsets t = List . fold_left ( fun offsets t0 -> Exported_offsets . merge offsets t0 . exported_offsets ) Exported_offsets . empty t
let functions_info t = List . fold_left ( fun code t0 -> Exported_code . merge code t0 . all_code ) Exported_code . empty t
let with_exported_offsets t exported_offsets = match t with | [ t0 ] -> [ { t0 with exported_offsets } ] | [ ] | _ :: _ :: _ -> Misc . fatal_error " Cannot set exported offsets on multiple units "
let update_for_pack0 ~ pack_units ~ pack t = let symbols = Symbol_importer . update_for_pack ~ pack_units ~ pack t . table_data . symbols in let variables = Variable_importer . update_for_pack ~ pack_units ~ pack t . table_data . variables in let simples = Simple_importer . update_for_pack ~ pa...
let update_for_pack ~ pack_units ~ pack t_opt = match t_opt with | None -> None | Some t -> Some ( List . map ( update_for_pack0 ~ pack_units ~ pack ) t )
let merge t1_opt t2_opt = match t1_opt , t2_opt with | None , None -> None | Some _ , None | None , Some _ -> Misc . fatal_error " Some pack units do not have their export info set . \ n \ Flambda doesn ' t support packing opaque and normal units together . " | Some t1 , Some t2 -> Som...
let print0 ppf t = Format . fprintf ppf " [ @< hov > Original unit :@ % a ] ; " @@ Compilation_unit . print t . original_compilation_unit ; Compilation_unit . set_current t . original_compilation_unit ; let typing_env , code = import_typing_env_and_code0 t in Format . fprintf ppf " ...
let [ @ ocamlformat " disable " ] print ppf t = let rec print_rest ppf = function | [ ] -> ( ) | t0 :: t -> Format . fprintf ppf " @ ( % a ) " print0 t0 ; print_rest ppf t in match t with | [ ] -> assert false | [ t0 ] -> print0 ppf t0 | t0 :: t -> Format . fprintf...
let colour_enabled = lazy ( let buf = Buffer . create 10 in let ppf = Format . formatter_of_buffer buf in Misc . Color . set_color_tag_handling ppf ; Format . fprintf ppf " { @< error } " ; >@%! String . length ( Buffer . contents buf ) > 0 )
let normal ( ) = if Lazy . force colour_enabled then " \ x1b [ 0m " else " "
let fg_256 n = if Lazy . force colour_enabled then Printf . sprintf " \ x1b [ 38 ; 5 ; % d ; 1m " n else " "
let bg_256 n = if Lazy . force colour_enabled then Printf . sprintf " \ x1b [ 48 ; 5 ; % d ; 1m " n else " "
let prim_constructive ( ) = fg_256 163
let prim_destructive ( ) = fg_256 62
let prim_neither ( ) = fg_256 130
let naked_number ( ) = fg_256 70
let tagged_immediate ( ) = fg_256 70
let constructor ( ) = fg_256 69
let kind ( ) = fg_256 37
let subkind ( ) = fg_256 39
let top_or_bottom_type ( ) = fg_256 37
let debuginfo ( ) = fg_256 243
let discriminant ( ) = fg_256 111
let name ( ) = fg_256 111
let parameter ( ) = fg_256 198
let symbol ( ) = fg_256 98
let variable ( ) = fg_256 111
let function_slot ( ) = fg_256 31
let value_slot ( ) = fg_256 43
let code_id ( ) = fg_256 169
let expr_keyword ( ) = fg_256 51
let invalid_keyword ( ) = fg_256 255 ^ bg_256 160
let static_keyword ( ) = fg_256 255 ^ bg_256 240
let static_part ( ) = fg_256 255 ^ bg_256 237
let continuation ( ) = fg_256 35
let continuation_definition ( ) = bg_256 237
let continuation_annotation ( ) = fg_256 202 ^ bg_256 237
let name_abstraction ( ) = fg_256 172
let rec_info ( ) = fg_256 249
let coercion ( ) = fg_256 249