text stringlengths 12 786k |
|---|
let get_int64_be b i = if not Sys . big_endian then swap64 ( get_int64_ne b i ) else get_int64_ne b i |
let set_int16_le b i x = if Sys . big_endian then set_int16_ne b i ( swap16 x ) else set_int16_ne b i x |
let set_int16_be b i x = if not Sys . big_endian then set_int16_ne b i ( swap16 x ) else set_int16_ne b i x |
let set_int32_le b i x = if Sys . big_endian then set_int32_ne b i ( swap32 x ) else set_int32_ne b i x |
let set_int32_be b i x = if not Sys . big_endian then set_int32_ne b i ( swap32 x ) else set_int32_ne b i x |
let set_int64_le b i x = if Sys . big_endian then set_int64_ne b i ( swap64 x ) else set_int64_ne b i x |
let set_int64_be b i x = if not Sys . big_endian then set_int64_ne b i ( swap64 x ) else set_int64_ne b i x |
type ' a ref = { mutable contents : ' a } = " caml_blit_bytes " [ @@ noalloc ] |
let extend len s left right r = let srcoff , dstoff = if left < 0 then - left , 0 else 0 , left in let cpylen = min ( length s - srcoff ) ( len - dstoff ) in if cpylen > 0 then unsafe_blit s srcoff r dstoff cpylen ; r |
let section_table = ref ( [ ] : ( string * int ) list ) |
let section_beginning = ref 0 |
let init_record outchan = section_beginning := pos_out outchan ; section_table := [ ] |
let record outchan name = let pos = pos_out outchan in section_table := ( name , pos - ! section_beginning ) :: ! section_table ; section_beginning := pos |
let write_toc_and_trailer outchan = List . iter ( fun ( name , len ) -> output_string outchan name ; output_binary_int outchan len ) ( List . rev ! section_table ) ; output_binary_int outchan ( List . length ! section_table ) ; output_string outchan Config . exec_magic_number ; section_table := [ ] ; |
let read_toc ic = let pos_trailer = in_channel_length ic - 16 in seek_in ic pos_trailer ; let num_sections = input_binary_int ic in let header = really_input_string ic ( String . length Config . exec_magic_number ) in if header <> Config . exec_magic_number then raise Bad_magic_number ; seek_in ic ( pos_trailer - 8 * num_sections ) ; section_table := [ ] ; for _i = 1 to num_sections do let name = really_input_string ic 4 in let len = input_binary_int ic in section_table := ( name , len ) :: ! section_table done |
let toc ( ) = List . rev ! section_table |
let seek_section ic name = let rec seek_sec curr_ofs = function [ ] -> raise Not_found | ( n , len ) :: rem -> if n = name then begin seek_in ic ( curr_ofs - len ) ; len end else seek_sec ( curr_ofs - len ) rem in seek_sec ( in_channel_length ic - 16 - 8 * List . length ! section_table ) ! section_table |
let read_section_string ic name = really_input_string ic ( seek_section ic name ) |
let read_section_struct ic name = ignore ( seek_section ic name ) ; input_value ic |
let pos_first_section ic = in_channel_length ic - 16 - 8 * List . length ! section_table - List . fold_left ( fun total ( _name , len ) -> total + len ) 0 ! section_table |
let reset ( ) = section_table := [ ] ; section_beginning := 0 |
type t = { names_to_types : ( Type_grammar . t * Binding_time . With_name_mode . t ) Name . Map . t ; aliases : Aliases . t ; symbol_projections : Symbol_projection . t Variable . Map . t } |
let print_kind_and_mode ~ min_binding_time ppf ( ty , binding_time_and_mode ) = let kind = Type_grammar . kind ty in let mode = Binding_time . With_name_mode . scoped_name_mode binding_time_and_mode ~ min_binding_time in Format . fprintf ppf " :: % a % a " Flambda_kind . print kind Name_mode . print mode |
let print_name_modes ~ restrict_to ~ min_binding_time ppf t = Name . Map . print ( print_kind_and_mode ~ min_binding_time ) ppf ( Name . Map . filter ( fun name _ -> Name . Set . mem name restrict_to ) t . names_to_types ) |
let empty = { names_to_types = Name . Map . empty ; aliases = Aliases . empty ; symbol_projections = Variable . Map . empty } |
let names_to_types t = t . names_to_types |
let aliases t = t . aliases |
let symbol_projections t = t . symbol_projections |
let add_or_replace_binding t ( name : Name . t ) ty binding_time name_mode = let binding_time_and_mode = Binding_time . With_name_mode . create binding_time name_mode in let names_to_types = Name . Map . add name ( ty , binding_time_and_mode ) t . names_to_types in { names_to_types ; aliases = t . aliases ; symbol_projections = t . symbol_projections } |
let replace_variable_binding t var ty = let names_to_types = Name . Map . replace ( Name . var var ) ( function _old_ty , binding_time_and_mode -> ty , binding_time_and_mode ) t . names_to_types in { names_to_types ; aliases = t . aliases ; symbol_projections = t . symbol_projections } |
let with_aliases t ~ aliases = { t with aliases } |
let add_symbol_projection t var proj = let symbol_projections = Variable . Map . add var proj t . symbol_projections in { t with symbol_projections } |
let find_symbol_projection t var = match Variable . Map . find var t . symbol_projections with | exception Not_found -> None | proj -> Some proj |
let clean_for_export t ~ reachable_names = let current_compilation_unit = Compilation_unit . get_current_exn ( ) in let names_to_types = Name . Map . filter ( fun name _info -> Name_occurrences . mem_name reachable_names name && Compilation_unit . equal ( Name . compilation_unit name ) current_compilation_unit ) t . names_to_types in let aliases = Aliases . clean_for_export t . aliases ~ reachable_names in { t with names_to_types ; aliases } |
let apply_renaming { names_to_types ; aliases ; symbol_projections } renaming = let names_to_types = Name . Map . fold ( fun name ( ty , binding_time_and_mode ) acc -> Name . Map . add ( Renaming . apply_name renaming name ) ( Type_grammar . apply_renaming ty renaming , binding_time_and_mode ) acc ) names_to_types Name . Map . empty in let aliases = Aliases . apply_renaming aliases renaming in let symbol_projections = Variable . Map . fold ( fun var proj acc -> Variable . Map . add ( Renaming . apply_variable renaming var ) ( Symbol_projection . apply_renaming proj renaming ) acc ) symbol_projections Variable . Map . empty in { names_to_types ; aliases ; symbol_projections } |
let merge t1 t2 = let names_to_types = Name . Map . disjoint_union t1 . names_to_types t2 . names_to_types in let aliases = Aliases . merge t1 . aliases t2 . aliases in let symbol_projections = Variable . Map . union ( fun var proj1 proj2 -> if Symbol_projection . equal proj1 proj2 then Some proj1 else Misc . fatal_errorf " Cannot merge symbol projections for % a :@ % a @ and @ % a " Variable . print var Symbol_projection . print proj1 Symbol_projection . print proj2 ) t1 . symbol_projections t2 . symbol_projections in { names_to_types ; aliases ; symbol_projections } |
let canonicalise t simple = Simple . pattern_match simple ~ const ( : fun _ -> simple ) ~ name ( : fun name ~ coercion -> Simple . apply_coercion_exn ( Aliases . get_canonical_ignoring_name_mode t . aliases name ) coercion ) |
let remove_unused_value_slots_and_shortcut_aliases ( { names_to_types ; aliases ; symbol_projections } as t ) ~ used_value_slots = let canonicalise = canonicalise t in let names_to_types = Name . Map . map_sharing ( fun ( ( ty , binding_time_and_mode ) as info ) -> let ty ' = Type_grammar . remove_unused_value_slots_and_shortcut_aliases ty ~ used_value_slots ~ canonicalise in if ty == ty ' then info else ty ' , binding_time_and_mode ) names_to_types in { names_to_types ; aliases ; symbol_projections } |
let free_function_slots_and_value_slots { names_to_types ; aliases = _ ; symbol_projections } = let from_projections = Variable . Map . fold ( fun _var proj free_names -> Name_occurrences . union free_names ( Name_occurrences . restrict_to_value_slots_and_function_slots ( Symbol_projection . free_names proj ) ) ) symbol_projections Name_occurrences . empty in Name . Map . fold ( fun _name ( ty , _binding_time ) free_names -> let free_names_of_ty = Type_grammar . free_names ty in Name_occurrences . union free_names ( Name_occurrences . restrict_to_value_slots_and_function_slots free_names_of_ty ) ) names_to_types from_projections |
let mem_string ~ elt : c s = try for i = 0 to String . length s - 1 do if s . [ i ] = c then raise Exit done ; false with Exit -> true |
let ops = [ ' ' , ( . ) ; ++ ' ' , ( . ) ; -- ' ' , ( * . ) ; * ' ' , ( . ) ] // val variable = Textvariable . create ( ) val mutable x = 0 . 0 val mutable op = None val mutable displaying = true method set = Textvariable . set variable method get = Textvariable . get variable method insert s = calc # set ( calc # get ^ s ) method get_float = float_of_string ( calc # get ) method command s = if s <> " " then match s . [ 0 ] with ' 0 ' . . ' 9 ' -> if displaying then ( calc # set " " ; displaying <- false ) ; calc # insert s | ' . ' -> if displaying then ( calc # set " 0 . " ; displaying <- false ) else if not ( mem_string ~ elt ' . ' : calc # get ) then calc # insert s | ' ' ' ' ' ' ' ' +|-|*|/ as c -> displaying <- true ; begin match op with None -> x <- calc # get_float ; op <- Some ( List . assoc c ops ) | Some f -> x <- f x ( calc # get_float ) ; op <- Some ( List . assoc c ops ) ; calc # set ( Printf . sprintf " % g " x ) end | ' ' ' =|\ n ' ' |\ r ' -> displaying <- true ; begin match op with None -> ( ) | Some f -> x <- f x ( calc # get_float ) ; op <- None ; calc # set ( Printf . sprintf " % g " x ) end | ' q ' -> closeTk ( ) ; exit 0 | _ -> ( ) end |
let m = [ [ " | 7 " ; " 8 " ; " 9 " ; " " ] ; + [ " 4 " ; " 5 " ; " 6 " ; " " ] ; - [ " 1 " ; " 2 " ; " 3 " ; " " ] ; * [ " 0 " ; " . " ; " " ; " " ] ] =/| inherit calc ( ) as calc val label = Label . create ~ anchor ` : E ~ relief ` : Sunken ~ padx : 10 parent val frame = Frame . create parent initializer let buttons = Array . map ~ f : ( List . map ~ f : ( fun text -> Button . create ~ text ~ command ( : fun ( ) -> calc # command text ) frame ) ) m in Label . configure ~ textvariable : variable label ; calc # set " 0 " ; bind ~ events [ ` : KeyPress ] ~ fields [ ` : Char ] ~ action ( : fun ev -> calc # command ev . ev_Char ) parent ; for i = 0 to Array . length m - 1 do Grid . configure ~ row : i buttons . ( i ) done ; pack ~ side ` : Top ~ fill ` : X [ label ] ; pack ~ side ` : Bottom ~ fill ` : Both ~ expand : true [ frame ] ; end |
let top = openTk ( ) |
let applet = new calculator ~ parent : top |
let _ = mainLoop ( ) |
module Mode = struct type t = | Disabled | Top_of_stack | Full_trace end |
let mode = ref ( if Base . Exported_for_specific_uses . am_testing then Mode . Disabled else Top_of_stack ) ; ; |
let set_mode m = mode := m |
type t = | Top_of_stack of Printexc . location | Full_trace of Printexc . location option list |
let sexp_of_location ( t : Printexc . location ) = let loc = Printf . sprintf " % s :% i :% i " t . filename t . line_number t . start_char in [ % sexp ( loc : string ) ] ; ; |
let sexp_of_t ( t : t ) = match t with | Top_of_stack s -> [ % sexp ( s : location ) ] | Full_trace s -> [ % sexp ( s : location option list ) ] ; ; |
let get ( ? skip = [ ] ) ( ) = let skip = " list . ml " :: " list0 . ml " :: " array . ml " :: " comb . ml " :: " interface . ml " :: " signal . ml " :: " bits . ml " :: " with_valid . ml " :: " scope . ml " :: " parameter . ml " :: " hierarchy . ml " :: Caml . __FILE__ :: skip in let stack = Printexc . get_callstack 16 in let len = Printexc . raw_backtrace_length stack in let rec top pos = if pos = len then None else ( match Printexc . get_raw_backtrace_slot stack pos |> Printexc . convert_raw_backtrace_slot |> Printexc . Slot . location with | None -> None | Some loc -> if List . mem ~ equal : String . equal skip loc . filename then top ( pos + 1 ) else Some loc ) in let rec full pos = if pos = len then [ ] else ( Printexc . get_raw_backtrace_slot stack pos |> Printexc . convert_raw_backtrace_slot |> Printexc . Slot . location ) :: full ( pos + 1 ) in match ! mode with | Disabled -> None | Top_of_stack -> top 0 |> Option . map ~ f ( : fun s -> Top_of_stack s ) | Full_trace -> Some ( Full_trace ( full 0 ) ) ; ; |
let check_arity arity = if Flambda_arity . With_subkinds . is_nullary arity then Misc . fatal_error " Invalid nullary arity " |
module Function_call = struct type t = | Direct of { code_id : Code_id . t ; return_arity : Flambda_arity . With_subkinds . t } | Indirect_unknown_arity | Indirect_known_arity of { param_arity : Flambda_arity . With_subkinds . t ; return_arity : Flambda_arity . With_subkinds . t } let [ @ ocamlformat " disable " ] print ppf call = match call with | Direct { code_id ; return_arity ; } -> fprintf ppf " [ @< hov 1 ( > Direct @ \ [ @< hov 1 ( > code_id @ % a ) ] @@ \ [ @< hov 1 ( > return_arity @ % a ) ] @\ ) ] " @ Code_id . print code_id Flambda_arity . With_subkinds . print return_arity | Indirect_unknown_arity -> fprintf ppf " Indirect_unknown_arity " | Indirect_known_arity { param_arity ; return_arity ; } -> fprintf ppf " [ @< hov 1 ( > Indirect_known_arity % a \ u { 2192 } % a ) ] " @ Flambda_arity . With_subkinds . print param_arity Flambda_arity . With_subkinds . print return_arity let return_arity call = match call with | Direct { return_arity ; _ } | Indirect_known_arity { return_arity ; _ } -> return_arity | Indirect_unknown_arity -> Flambda_arity . With_subkinds . create [ Flambda_kind . With_subkind . any_value ] end |
type method_kind = | Self | Public | Cached |
let print_method_kind ppf kind = match kind with | Self -> fprintf ppf " Self " | Public -> fprintf ppf " Public " | Cached -> fprintf ppf " Cached " |
let method_kind_from_lambda ( kind : Lambda . meth_kind ) = match kind with Self -> Self | Public -> Public | Cached -> Cached |
type t = | Function of { function_call : Function_call . t ; alloc_mode : Alloc_mode . t } | Method of { kind : method_kind ; obj : Simple . t ; alloc_mode : Alloc_mode . t } | C_call of { alloc : bool ; param_arity : Flambda_arity . t ; return_arity : Flambda_arity . t ; is_c_builtin : bool } |
let [ @ ocamlformat " disable " ] print ppf t = match t with | Function { function_call ; alloc_mode } -> fprintf ppf " [ @< hov 1 ( > Function @ \ [ @< hov 1 ( > function_call @ % a ) ] @@ \ [ @< hov 1 ( > alloc_mode @ % a ) ] @\ ) ] " @ Function_call . print function_call Alloc_mode . print alloc_mode | Method { kind ; obj ; alloc_mode } -> fprintf ppf " [ @< hov 1 ( > Method @ \ [ @< hov 1 ( > obj @ % a ) ] @@ \ [ @< hov 1 ( > kind @ % a ) ] @@ \ [ @< hov 1 ( > alloc_mode @ % a ) ] @\ ) ] " @ Simple . print obj print_method_kind kind Alloc_mode . print alloc_mode | C_call { alloc ; param_arity ; return_arity ; is_c_builtin ; } -> fprintf ppf " [ ( @ C @ [ ( @ alloc % b ) ] @@ [ ( @ is_c_builtin % b ) ] @@ \ @< 0 >% s @< 1 >\ u { 2237 } @< 0 >% s % a @< 1 >\ u { 2192 } % a ) ] " @ alloc is_c_builtin ( Flambda_colours . elide ( ) ) ( Flambda_colours . normal ( ) ) Flambda_arity . print param_arity Flambda_arity . print return_arity |
let direct_function_call code_id ~ return_arity alloc_mode = check_arity return_arity ; Function { function_call = Direct { code_id ; return_arity } ; alloc_mode } |
let indirect_function_call_unknown_arity alloc_mode = Function { function_call = Indirect_unknown_arity ; alloc_mode } |
let indirect_function_call_known_arity ~ param_arity ~ return_arity alloc_mode = check_arity return_arity ; Function { function_call = Indirect_known_arity { param_arity ; return_arity } ; alloc_mode } |
let method_call kind ~ obj alloc_mode = Method { kind ; obj ; alloc_mode } |
let c_call ~ alloc ~ param_arity ~ return_arity ~ is_c_builtin = begin match Flambda_arity . to_list return_arity with | [ ] | [ _ ] -> ( ) | _ :: _ :: _ -> Misc . fatal_errorf " Illegal return arity for C call : % a " Flambda_arity . print return_arity end ; C_call { alloc ; param_arity ; return_arity ; is_c_builtin } |
let return_arity t = match t with | Function { function_call ; _ } -> Function_call . return_arity function_call | Method _ -> Flambda_arity . With_subkinds . create [ Flambda_kind . With_subkind . any_value ] | C_call { return_arity ; _ } -> Flambda_arity . With_subkinds . of_arity return_arity |
let free_names t = match t with | Function { function_call = Direct { code_id ; return_arity = _ } ; alloc_mode = _ } -> Name_occurrences . add_code_id Name_occurrences . empty code_id Name_mode . normal | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } | Function { function_call = Indirect_known_arity { param_arity = _ ; return_arity = _ } ; alloc_mode = _ } | C_call { alloc = _ ; param_arity = _ ; return_arity = _ ; is_c_builtin = _ } -> Name_occurrences . empty | Method { kind = _ ; obj ; alloc_mode = _ } -> Simple . pattern_match obj ~ name ( : fun obj ~ coercion : _ -> Name_occurrences . singleton_name obj Name_mode . normal ) ~ const ( : fun _ -> Name_occurrences . empty ) |
let apply_renaming t perm = match t with | Function { function_call = Direct { code_id ; return_arity } ; alloc_mode } -> let code_id ' = Renaming . apply_code_id perm code_id in if code_id == code_id ' then t else Function { function_call = Direct { code_id = code_id ' ; return_arity } ; alloc_mode } | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } | Function { function_call = Indirect_known_arity { param_arity = _ ; return_arity = _ } ; alloc_mode = _ } | C_call { alloc = _ ; param_arity = _ ; return_arity = _ ; is_c_builtin = _ } -> t | Method { kind ; obj ; alloc_mode } -> let obj ' = Simple . apply_renaming obj perm in if obj == obj ' then t else Method { kind ; obj = obj ' ; alloc_mode } |
let all_ids_for_export t = match t with | Function { function_call = Direct { code_id ; return_arity = _ } ; alloc_mode = _ } -> Ids_for_export . add_code_id Ids_for_export . empty code_id | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } | Function { function_call = Indirect_known_arity { param_arity = _ ; return_arity = _ } ; alloc_mode = _ } | C_call { alloc = _ ; param_arity = _ ; return_arity = _ ; is_c_builtin = _ } -> Ids_for_export . empty | Method { kind = _ ; obj ; alloc_mode = _ } -> Ids_for_export . from_simple obj |
let speculative_inlining dacc ~ apply ~ function_type ~ simplify_expr ~ return_arity = let dacc = DA . set_do_not_rebuild_terms_and_disable_inlining dacc in let dacc , expr = Inlining_transforms . inline dacc ~ apply ~ unroll_to : None function_type in let scope = DE . get_continuation_scope ( DA . denv dacc ) in let dummy_toplevel_cont = Continuation . create ~ name " : dummy_toplevel_continuation " ( ) in let dacc = DA . map_data_flow dacc ~ f ( : fun _ -> Data_flow . init_toplevel dummy_toplevel_cont [ ] Data_flow . empty ) in let _ , uacc = simplify_expr dacc expr ~ down_to_up ( : fun dacc ~ rebuild -> let exn_continuation = Apply . exn_continuation apply in let dacc = DA . map_data_flow dacc ~ f ( : Data_flow . exit_continuation dummy_toplevel_cont ) in let data_flow = DA . data_flow dacc in let function_return_cont = match Apply . continuation apply with | Never_returns -> Continuation . create ( ) | Return cont -> cont in let ( { required_names ; reachable_code_ids = _ } : Data_flow . result ) = Data_flow . analyze data_flow ~ code_age_relation : Code_age_relation . empty ~ used_value_slots : Unknown ~ return_continuation : function_return_cont ~ exn_continuation ( : Exn_continuation . exn_handler exn_continuation ) in let uenv = UE . add_function_return_or_exn_continuation ( UE . create ( DA . are_rebuilding_terms dacc ) ) ( Exn_continuation . exn_handler exn_continuation ) scope ( Flambda_arity . With_subkinds . create [ Flambda_kind . With_subkind . any_value ] ) in let uenv = match Apply . continuation apply with | Never_returns -> uenv | Return return_continuation -> UE . add_function_return_or_exn_continuation uenv return_continuation scope return_arity in let uacc = UA . create ~ required_names ~ reachable_code_ids : Unknown ~ compute_slot_offsets : false uenv dacc in rebuild uacc ~ after_rebuild ( : fun expr uacc -> expr , uacc ) ) in UA . cost_metrics uacc |
let argument_types_useful dacc apply = if not ( Flambda_features . Inlining . speculative_inlining_only_if_arguments_useful ( ) ) then true else let typing_env = DE . typing_env ( DA . denv dacc ) in List . exists ( fun simple -> Simple . pattern_match simple ~ name ( : fun name ~ coercion : _ -> let ty = TE . find typing_env name None in not ( T . is_unknown typing_env ty ) ) ~ const ( : fun _ -> true ) ) ( Apply . args apply ) |
let might_inline dacc ~ apply ~ code_or_metadata ~ function_type ~ simplify_expr ~ return_arity : Call_site_inlining_decision_type . t = let denv = DA . denv dacc in let env_prohibits_inlining = not ( DE . can_inline denv ) in let decision = Code_or_metadata . code_metadata code_or_metadata |> Code_metadata . inlining_decision in if Function_decl_inlining_decision_type . must_be_inlined decision then Definition_says_inline else if Function_decl_inlining_decision_type . cannot_be_inlined decision then Definition_says_not_to_inline else if env_prohibits_inlining then Environment_says_never_inline else if not ( argument_types_useful dacc apply ) then Argument_types_not_useful else let cost_metrics = speculative_inlining ~ apply dacc ~ simplify_expr ~ return_arity ~ function_type in let inlining_args = Apply . inlining_arguments apply |> Inlining_arguments . meet ( DE . inlining_arguments denv ) in let evaluated_to = Cost_metrics . evaluate ~ args : inlining_args cost_metrics in let threshold = Inlining_arguments . threshold inlining_args in let is_under_inline_threshold = Float . compare evaluated_to threshold <= 0 in if is_under_inline_threshold then Speculatively_inline { cost_metrics ; evaluated_to ; threshold } else Speculatively_not_inline { cost_metrics ; evaluated_to ; threshold } |
let get_rec_info dacc ~ function_type = let rec_info = FT . rec_info function_type in match Flambda2_types . prove_rec_info ( DA . typing_env dacc ) rec_info with | Proved rec_info -> rec_info | Unknown -> Rec_info_expr . unknown | Invalid -> Rec_info_expr . do_not_inline |
let make_decision dacc ~ simplify_expr ~ function_type ~ apply ~ return_arity : Call_site_inlining_decision_type . t = let rec_info = get_rec_info dacc ~ function_type in let inlined = Apply . inlined apply in match inlined with | Never_inlined -> Never_inlined_attribute | Default_inlined | Unroll _ | Always_inlined | Hint_inlined -> ( let code_or_metadata = DE . find_code_exn ( DA . denv dacc ) ( FT . code_id function_type ) in if not ( Code_or_metadata . code_present code_or_metadata ) then Missing_code else let unrolling_depth = Simplify_rec_info_expr . known_remaining_unrolling_depth dacc rec_info in match unrolling_depth with | Some 0 -> Unrolling_depth_exceeded | Some _ -> might_inline dacc ~ apply ~ code_or_metadata ~ function_type ~ simplify_expr ~ return_arity | None -> ( let apply_inlining_state = Apply . inlining_state apply in if Inlining_state . is_depth_exceeded apply_inlining_state then Max_inlining_depth_exceeded else match inlined with | Never_inlined -> assert false | Default_inlined -> let max_rec_depth = Flambda_features . Inlining . max_rec_depth ( Round ( DE . round ( DA . denv dacc ) ) ) in if Simplify_rec_info_expr . depth_may_be_at_least dacc rec_info max_rec_depth then Recursion_depth_exceeded else might_inline dacc ~ apply ~ code_or_metadata ~ function_type ~ simplify_expr ~ return_arity | Unroll unroll_to -> if Simplify_rec_info_expr . can_unroll dacc rec_info then Attribute_unroll unroll_to else Unrolling_depth_exceeded | Always_inlined | Hint_inlined -> Attribute_always ) ) |
type t = | Missing_code | Definition_says_not_to_inline | Environment_says_never_inline | Argument_types_not_useful | Unrolling_depth_exceeded | Max_inlining_depth_exceeded | Recursion_depth_exceeded | Never_inlined_attribute | Speculatively_not_inline of { cost_metrics : Cost_metrics . t ; evaluated_to : float ; threshold : float } | Attribute_always | Attribute_unroll of int | Definition_says_inline | Speculatively_inline of { cost_metrics : Cost_metrics . t ; evaluated_to : float ; threshold : float } |
let [ @ ocamlformat " disable " ] print ppf t = match t with | Missing_code -> Format . fprintf ppf " Missing_code " | Definition_says_not_to_inline -> Format . fprintf ppf " Definition_says_not_to_inline " | Environment_says_never_inline -> Format . fprintf ppf " Environment_says_never_inline " | Argument_types_not_useful -> Format . fprintf ppf " Argument_types_not_useful " | Unrolling_depth_exceeded -> Format . fprintf ppf " Unrolling_depth_exceeded " | Max_inlining_depth_exceeded -> Format . fprintf ppf " Max_inlining_depth_exceeded " | Recursion_depth_exceeded -> Format . fprintf ppf " Recursion_depth_exceeded " | Never_inlined_attribute -> Format . fprintf ppf " Never_inlined_attribute " | Attribute_always -> Format . fprintf ppf " Attribute_unroll " | Definition_says_inline -> Format . fprintf ppf " Definition_says_inline " | Attribute_unroll unroll_to -> Format . fprintf ppf " [ @< hov 1 ( > Attribute_unroll @ \ [ @< hov 1 ( > unroll_to @ % d ) ] @\ ) ] " @ unroll_to | Speculatively_not_inline { cost_metrics ; threshold ; evaluated_to ; } -> Format . fprintf ppf " [ @< hov 1 ( > Speculatively_not_inline @ \ [ @< hov 1 ( > cost_metrics @ % a ) ] @@ \ [ @< hov 1 ( > evaluated_to @ % f ) ] @@ \ [ @< hov 1 ( > threshold @ % f ) ] @\ ) ] " @ Cost_metrics . print cost_metrics evaluated_to threshold | Speculatively_inline { cost_metrics ; threshold ; evaluated_to ; } -> Format . fprintf ppf " [ @< hov 1 ( > Speculatively_inline @ \ [ @< hov 1 ( > cost_metrics @ % a ) ] @@ \ [ @< hov 1 ( > evaluated_to @ % f ) ] @@ \ [ @< hov 1 ( > threshold @ % f ) ] @\ ) ] " @ Cost_metrics . print cost_metrics evaluated_to threshold |
type can_inline = | Do_not_inline of { warn_if_attribute_ignored : bool ; because_of_definition : bool } | Inline of { unroll_to : int option } |
let can_inline ( t : t ) : can_inline = match t with | Missing_code | Environment_says_never_inline | Max_inlining_depth_exceeded | Recursion_depth_exceeded | Speculatively_not_inline _ | Definition_says_not_to_inline | Argument_types_not_useful -> Do_not_inline { warn_if_attribute_ignored = true ; because_of_definition = true } | Never_inlined_attribute -> Do_not_inline { warn_if_attribute_ignored = true ; because_of_definition = true } | Unrolling_depth_exceeded -> Do_not_inline { warn_if_attribute_ignored = false ; because_of_definition = true } | Attribute_unroll unroll_to -> Inline { unroll_to = Some unroll_to } | Definition_says_inline | Speculatively_inline _ | Attribute_always -> Inline { unroll_to = None } |
let report_reason fmt t = match ( t : t ) with | Missing_code -> Format . fprintf fmt " the @ code @ could @ not @ be @ found @ ( is @ a @ . cmx @ file @ missing ) " ? | Definition_says_not_to_inline -> Format . fprintf fmt " this @ function @ was @ deemed @ at @ the @ point @ of @ its @ definition @ to @ \ never @ be @ inlinable " | Environment_says_never_inline -> Format . fprintf fmt " the @ environment @ says @ never @ to @ inline " | Argument_types_not_useful -> Format . fprintf fmt " there @ was @ no @ useful @ information @ about @ the @ arguments " | Unrolling_depth_exceeded -> Format . fprintf fmt " the @ maximum @ unrolling @ depth @ has @ been @ exceeded " | Max_inlining_depth_exceeded -> Format . fprintf fmt " the @ maximum @ inlining @ depth @ has @ been @ exceeded " | Recursion_depth_exceeded -> Format . fprintf fmt " the @ maximum @ recursion @ depth @ has @ been @ exceeded " | Never_inlined_attribute -> Format . fprintf fmt " the @ call @ has @ an @ attribute @ forbidding @ inlining " | Attribute_always -> Format . fprintf fmt " the @ call @ has @ an @ [ @@ inline always ] @ attribute " | Attribute_unroll n -> Format . fprintf fmt " the @ call @ has @ an @ [ @@ unroll % d ] @ attribute " n | Definition_says_inline -> Format . fprintf fmt " this @ function @ was @ decided @ to @ be @ always @ inlined @ at @ its @ \ definition @ site ( annotated @ by @ [ @ inlined always ] @ or @ determined @ to @ \ be @ small @ enough ) " | Speculatively_not_inline { cost_metrics ; evaluated_to ; threshold } -> Format . fprintf fmt " the @ function @ was @ not @ inlined @ after @ speculation @ as @ its @ cost @ \ metrics were =% a , @ which @ was @ evaluated @ to @ % f > threshold % f " Cost_metrics . print cost_metrics evaluated_to threshold | Speculatively_inline { cost_metrics ; evaluated_to ; threshold } -> Format . fprintf fmt " the @ function @ was @ inlined @ after @ speculation @ as @ its @ cost @ metrics \ were =% a , @ which @ was @ evaluated @ to @ % f <= threshold % f " Cost_metrics . print cost_metrics evaluated_to threshold |
let report fmt t = Format . fprintf fmt " [ @< v > The function call % s been inlined @ because [ @< hov >% a ] ] " @@ ( match can_inline t with Inline _ -> " has " | Do_not_inline _ -> " has not " ) report_reason t |
type ' a t = { mutable v : ' a } |
let make v = { v } |
let get r = r . v |
let set r v = r . v <- v let cur = r . v in r . v <- v ; cur let cur = r . v in if cur == seen then ( r . v <- v ; true ) else false let cur = r . v in r . v <- ( cur + n ) ; cur |
let incr r = ignore ( fetch_and_add r 1 ) |
let decr r = ignore ( fetch_and_add r ( - 1 ) ) |
let create_char_set ( ) = Bytes . make 32 ' \ 000 ' |
let add_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in Bytes . set char_set str_ind ( char_of_int ( int_of_char ( Bytes . get char_set str_ind ) lor mask ) ) |
let freeze_char_set char_set = Bytes . to_string char_set |
let rev_char_set char_set = let char_set ' = create_char_set ( ) in for i = 0 to 31 do Bytes . set char_set ' i ( char_of_int ( int_of_char ( String . get char_set i ) lxor 0xFF ) ) ; done ; Bytes . unsafe_to_string char_set ' |
let is_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in ( int_of_char ( String . get char_set str_ind ) land mask ) <> 0 |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb = Param_format_EBB : ( ' x -> ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb |
let pad_of_pad_opt pad_opt = match pad_opt with | None -> No_padding | Some width -> Lit_padding ( Right , width ) |
let prec_of_prec_opt prec_opt = match prec_opt with | None -> No_precision | Some ndec -> Lit_precision ndec |
let param_format_of_ignored_format : type a b c d e f x y . ( a , b , c , d , y , x ) ignored -> ( x , b , c , y , e , f ) fmt -> ( a , b , c , d , e , f ) param_format_ebb = | Ignored_char -> Param_format_EBB ( Char fmt ) | Ignored_caml_char -> Param_format_EBB ( Caml_char fmt ) | Ignored_string pad_opt -> Param_format_EBB ( String ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_caml_string pad_opt -> Param_format_EBB ( Caml_string ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_int ( iconv , pad_opt ) -> Param_format_EBB ( Int ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_int32 ( iconv , pad_opt ) -> Param_format_EBB ( Int32 ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_nativeint ( iconv , pad_opt ) -> Param_format_EBB ( Nativeint ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_int64 ( iconv , pad_opt ) -> Param_format_EBB ( Int64 ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_float ( pad_opt , prec_opt ) -> Param_format_EBB ( Float ( ( Float_flag_ , Float_f ) , pad_of_pad_opt pad_opt , prec_of_prec_opt prec_opt , fmt ) ) | Ignored_bool pad_opt -> Param_format_EBB ( Bool ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_format_arg ( pad_opt , fmtty ) -> Param_format_EBB ( Format_arg ( pad_opt , fmtty , fmt ) ) | Ignored_format_subst ( pad_opt , fmtty ) -> Param_format_EBB ( Format_subst ( pad_opt , fmtty , fmt ) ) | Ignored_reader -> Param_format_EBB ( Reader fmt ) | Ignored_scan_char_set ( width_opt , char_set ) -> Param_format_EBB ( Scan_char_set ( width_opt , char_set , fmt ) ) | Ignored_scan_get_counter counter -> Param_format_EBB ( Scan_get_counter ( counter , fmt ) ) | Ignored_scan_next_char -> Param_format_EBB ( Scan_next_char fmt ) |
type ( ' b , ' c ) acc_formatting_gen = | Acc_open_tag of ( ' b , ' c ) acc | Acc_open_box of ( ' b , ' c ) acc | Acc_formatting_lit of ( ' b , ' c ) acc * formatting_lit | Acc_formatting_gen of ( ' b , ' c ) acc * ( ' b , ' c ) acc_formatting_gen | Acc_string_literal of ( ' b , ' c ) acc * string | Acc_char_literal of ( ' b , ' c ) acc * char | Acc_data_string of ( ' b , ' c ) acc * string | Acc_data_char of ( ' b , ' c ) acc * char | Acc_delay of ( ' b , ' c ) acc * ( ' b -> ' c ) | Acc_flush of ( ' b , ' c ) acc | Acc_invalid_arg of ( ' b , ' c ) acc * string | End_of_acc |
type ( ' a , ' b ) heter_list = | Cons : ' c * ( ' a , ' b ) heter_list -> ( ' c -> ' a , ' b ) heter_list | Nil : ( ' b , ' b ) heter_list |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb = Padding_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb = Padprec_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' z ) precision * ( ' z , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb |
type ( ' a , ' b , ' c , ' e , ' f ) padding_fmt_ebb = Padding_fmt_EBB : ( _ , ' x -> ' a ) padding * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) padding_fmt_ebb |
type ( ' a , ' b , ' c , ' e , ' f ) precision_fmt_ebb = Precision_fmt_EBB : ( _ , ' x -> ' a ) precision * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) precision_fmt_ebb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.