text
stringlengths
12
786k
let map_named f_named tree = map ( fun expr -> expr ) f_named tree
let map_named_with_id f_named tree = map_general ~ toplevel : false ( fun expr -> expr ) f_named tree
let map_toplevel f f_named tree = map_general ~ toplevel : true f ( fun _ n -> f_named n ) tree
let map_toplevel_expr f_expr tree = map_toplevel f_expr ( fun named -> named ) tree
let map_toplevel_named f_named tree = map_toplevel ( fun tree -> tree ) f_named tree
let map_symbols tree ~ f = map_named ( function | ( Symbol sym ) as named -> let new_sym = f sym in if new_sym == sym then named else Symbol new_sym | ( ( Read_symbol_field ( sym , field ) ) as named ) -> let new_sym = f sym in if new_sym == sym then named else Read_symbol_field ( new_sy...
let map_symbols_on_set_of_closures ( { Flambda . function_decls ; free_vars ; specialised_args ; direct_call_surrogates ; } as set_of_closures ) ~ f = let done_something = ref false in let funs = Variable . Map . map ( fun ( func_decl : Flambda . function_declaration ) -> let body =...
let map_toplevel_sets_of_closures tree ~ f = map_toplevel_named ( function | ( Set_of_closures set_of_closures ) as named -> let new_set_of_closures = f set_of_closures in if new_set_of_closures == set_of_closures then named else Set_of_closures new_set_of_closures | ( Symbol _ | Const _ | Allocated_...
let map_apply tree ~ f = map ( function | ( Apply apply ) as expr -> let new_apply = f apply in if new_apply == apply then expr else Apply new_apply | expr -> expr ) ( fun named -> named ) tree
let map_sets_of_closures tree ~ f = map_named ( function | ( Set_of_closures set_of_closures ) as named -> let new_set_of_closures = f set_of_closures in if new_set_of_closures == set_of_closures then named else Set_of_closures new_set_of_closures | ( Symbol _ | Const _ | Allocated_const _ | Projec...
let map_project_var_to_expr_opt tree ~ f = map_named ( function | ( Project_var project_var ) as named -> begin match f project_var with | None -> named | Some expr -> Expr expr end | ( Symbol _ | Const _ | Allocated_const _ | Set_of_closures _ | Project_closure _ | Move_within_set_of_closure...
let map_project_var_to_named_opt tree ~ f = map_named ( function | ( Project_var project_var ) as named -> begin match f project_var with | None -> named | Some named -> named end | ( Symbol _ | Const _ | Allocated_const _ | Set_of_closures _ | Project_closure _ | Move_within_set_of_closures ...
let map_function_bodies ( set_of_closures : Flambda . set_of_closures ) ~ f = let done_something = ref false in let funs = Variable . Map . map ( fun ( function_decl : Flambda . function_declaration ) -> let new_body = f function_decl . body in if new_body == function_decl . body then fun...
let map_sets_of_closures_of_program ( program : Flambda . program ) ( ~ f : Flambda . set_of_closures -> Flambda . set_of_closures ) = let rec loop ( program : Flambda . program_body ) : Flambda . program_body = let map_constant_set_of_closures ( set_of_closures : Flambda . set_of_clo...
let map_exprs_at_toplevel_of_program ( program : Flambda . program ) ( ~ f : Flambda . t -> Flambda . t ) = let rec loop ( program : Flambda . program_body ) : Flambda . program_body = let map_constant_set_of_closures ( set_of_closures : Flambda . set_of_closures ) = let done_somet...
let map_named_of_program ( program : Flambda . program ) ( ~ f : Variable . t -> Flambda . named -> Flambda . named ) : Flambda . program = map_exprs_at_toplevel_of_program program ~ f ( : fun expr -> map_named_with_id f expr )
let map_all_immutable_let_and_let_rec_bindings ( expr : Flambda . t ) ( ~ f : Variable . t -> Flambda . named -> Flambda . named ) : Flambda . t = map_named_with_id f expr
let fold_function_decls_ignoring_stubs ( set_of_closures : Flambda . set_of_closures ) ~ init ~ f = Variable . Map . fold ( fun fun_var function_decl acc -> f ~ fun_var ~ function_decl acc ) set_of_closures . function_decls . funs init
module Naked_number_kind = struct type t = | Naked_immediate | Naked_float | Naked_int32 | Naked_int64 | Naked_nativeint let print ppf t = match t with | Naked_immediate -> Format . pp_print_string ppf " Naked_immediate " | Naked_float -> Format . pp_print_string ppf " Naked_float " | Naked_int...
type t = | Value | Naked_number of Naked_number_kind . t | Region | Rec_info
let naked_immediate = Naked_number Naked_immediate
let naked_float = Naked_number Naked_float
let naked_int32 = Naked_number Naked_int32
let naked_int64 = Naked_number Naked_int64
let naked_nativeint = Naked_number Naked_nativeint
let rec_info = Rec_info type nonrec t = t let compare = Stdlib . compare let equal t1 t2 = compare t1 t2 = 0 let hash = Hashtbl . hash let print ppf t = let colour = Flambda_colours . kind ( ) in match t with | Value -> if Flambda_features . unicode ( ) then Format . fprintf ppf " @< 0 ...
let is_value t = match t with Value -> true | Naked_number _ | Region | Rec_info -> false
let is_naked_float t = match t with | Naked_number Naked_float -> true | Value | Naked_number ( Naked_immediate | Naked_int32 | Naked_int64 | Naked_nativeint ) | Region | Rec_info -> false
module Standard_int = struct type t = | Tagged_immediate | Naked_immediate | Naked_int32 | Naked_int64 | Naked_nativeint let to_kind t : kind = match t with | Tagged_immediate -> Value | Naked_immediate -> Naked_number Naked_immediate | Naked_int32 -> Naked_number Naked_int32 | Naked_int64 -> Naked_num...
module Standard_int_or_float = struct type t = | Tagged_immediate | Naked_immediate | Naked_float | Naked_int32 | Naked_int64 | Naked_nativeint let to_kind t : kind = match t with | Tagged_immediate -> Value | Naked_immediate -> Naked_number Naked_immediate | Naked_float -> Naked_number Naked_float | N...
module Boxable_number = struct type t = | Naked_float | Naked_int32 | Naked_int64 | Naked_nativeint let unboxed_kind t : kind = match t with | Naked_float -> Naked_number Naked_float | Naked_int32 -> Naked_number Naked_int32 | Naked_int64 -> Naked_number Naked_int64 | Naked_nativeint -> Naked_number Nak...
module With_subkind = struct module Subkind = struct type t = | Anything | Boxed_float | Boxed_int32 | Boxed_int64 | Boxed_nativeint | Tagged_immediate | Block of { tag : Tag . t ; fields : t list } | Float_block of { num_fields : int } | Float_array | Immediate_array | Value_array | Gener...
type location = Lexing . position * Lexing . position
type error = | Illegal_character of char | Invalid_literal of string | No_such_primitive of string ; ;
let pp_error ppf = function | Illegal_character c -> Format . fprintf ppf " Illegal character % c " c | Invalid_literal s -> Format . fprintf ppf " Invalid literal % s " s | No_such_primitive s -> Format . fprintf ppf " No such primitive %%% s " s
let current_location lexbuf = ( Lexing . lexeme_start_p lexbuf , Lexing . lexeme_end_p lexbuf )
let error ~ lexbuf e = raise ( Error ( e , current_location lexbuf ) )
let create_hashtable init = let tbl = Hashtbl . create ( List . length init ) in List . iter ( fun ( key , data ) -> Hashtbl . add tbl key data ) init ; tbl
let keyword_table = create_hashtable [ " always " , KWD_ALWAYS ; " and " , KWD_AND ; " andwhere " , KWD_ANDWHERE ; " apply " , KWD_APPLY ; " asr " , KWD_ASR ; " available " , KWD_AVAILABLE ; " Block " , KWD_BLOCK ; " boxed " , KWD_BOXED ; " ccall " ...
let ident_or_keyword str = try Hashtbl . find keyword_table str with Not_found -> IDENT str
let is_keyword str = Hashtbl . mem keyword_table str
let prim_table = create_hashtable [ " array_length " , PRIM_ARRAY_LENGTH ; " array_load " , PRIM_ARRAY_LOAD ; " array_set " , PRIM_ARRAY_SET ; " Block " , PRIM_BLOCK ; " block_load " , PRIM_BLOCK_LOAD ; " Box_float " , PRIM_BOX_FLOAT ; " Box_int32 " , PRIM_BOX_IN...
let prim ~ lexbuf str = try Hashtbl . find prim_table str with Not_found -> error ~ lexbuf ( No_such_primitive str )
let unquote_ident str = match str with | " " -> " " | _ -> begin match String . get str 0 with | ' ` ' -> String . sub str 1 ( String . length str - 2 ) | _ -> str end
let symbol cunit_ident cunit_linkage_name ident = let cunit = Option . map ( fun cunit_ident -> { Fexpr . ident = unquote_ident cunit_ident ; linkage_name = Option . map unquote_ident cunit_linkage_name } ) cunit_ident in SYMBOL ( cunit , unquote_ident ident )
let __ocaml_lex_tables = { Lexing . lex_base = " \ 000 \ 000 \ 206 \ 255 \ 207 \ 255 \ 001 \ 000 \ 088 \ 000 \ 193 \ 000 \ 021 \ 001 \ 084 \ 000 \ \ 105 \ 001 \ 217 \ 255 \ 219 \ 255 \ 031 \ 000 \ 082 \ 000 \ 068 \ 000 \ 085 \ 000 \ 189 \ 001 \ ...
let rec token lexbuf = lexbuf . Lexing . lex_mem <- Array . make 12 ( - 1 ) ; __ocaml_lex_token_rec lexbuf 0 match Lexing . new_engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> ( Lexing . new_line lexbuf ; token lexbuf ) | 1 -> ( token lexbuf ) | 2 -> ( commen...
let _dump_function_sizes flam ~ backend = let module Backend = ( val backend : Backend_intf . S ) in let than = max_int in Flambda_iterators . iter_on_set_of_closures_of_program flam ~ f ( : fun ~ constant : _ ( set_of_closures : Flambda . set_of_closures ) -> Variable . Map . iter ( ...
let lambda_to_flambda ~ ppf_dump ~ prefixname ~ backend ~ size ~ filename ~ module_ident ~ module_initializer = Profile . record_call " flambda " ( fun ( ) -> let previous_warning_reporter = ! Location . warning_reporter in let module WarningSet = Set . Make ( struct type t = Location . ...
let flambda_raw_clambda_dump_if ppf ( { Flambda_to_clambda . expr = ulambda ; preallocated_blocks = _ ; structured_constants ; exported = _ ; } as input ) = if ! Clflags . dump_rawclambda then begin Format . fprintf ppf " . @ clambda ( before Un_anf ) . " ; :@ Printclambda ....
let lambda_to_clambda ~ backend ~ filename ~ prefixname ~ ppf_dump ( program : Lambda . program ) = let program = lambda_to_flambda ~ ppf_dump ~ prefixname ~ backend ~ size : program . main_module_block_size ~ filename ~ module_ident : program . module_ident ~ module_initializer : program . ...
module MenhirBasics = struct exception Error type token = | TILDE | SYMBOL of ( ( Fexpr . compilation_unit option * string ) ) | STRING of ( ( string ) ) | STARDOT | STAR | SLASHDOT | SLASH | SEMICOLON | RPAREN | RBRACKPIPE | RBRACE | QMARKDOT | QMARK | PRIM_UNTAG_IMM | PRIM_UNBOX_NA...
let make_loc ( startpos , endpos ) = Debuginfo . Scoped_location . of_location ~ scopes : Debuginfo . Scoped_location . empty_scopes { Location . loc_start = startpos ; Location . loc_end = endpos ; Location . loc_ghost = false ; }
let make_located txt ( startpos , endpos ) = let loc = make_loc ( startpos , endpos ) in { txt ; loc }
let make_plain_int = function | s , None -> Int64 . of_string s |> Int64 . to_int | _ , Some _ -> Misc . fatal_errorf " No modifier expected here "
let make_targetint = function | s , None -> Int64 . of_string s | _ , Some _ -> Misc . fatal_errorf " No modifier expected here "
let make_tag ~ loc : _ = function | s , None -> int_of_string s | _ , Some _ -> Misc . fatal_errorf " No modifier allowed for tags "
let make_tagged_immediate ~ loc : _ = function | s , None -> s | _ , _ -> Misc . fatal_errorf " Must be a tagged immediate "
let make_const_int ( i , m ) : const = match m with | None -> Tagged_immediate i | Some ' i ' -> Naked_immediate i | Some ' n ' -> Naked_nativeint ( Int64 . of_string i ) | Some ' l ' -> Naked_int32 ( Int32 . of_string i ) | Some ' L ' -> Naked_int64 ( Int64 . of_string...
let make_boxed_const_int ( i , m ) : static_data = match m with | None -> Misc . fatal_errorf " Need int modifier for static data " | Some ' n ' -> Boxed_nativeint ( Const ( Int64 . of_string i ) ) | Some ' l ' -> Boxed_int32 ( Const ( Int32 . of_string i ) ) | Some ' ...
module Tables = struct include MenhirBasics let token2terminal : token -> int = fun _tok -> match _tok with | AT -> 143 | BIGARROW -> 142 | BLANK -> 141 | COLON -> 140 | COMMA -> 139 | DOT -> 138 | EOF -> 137 | EQUAL -> 136 | EQUALDOT -> 135 | FLOAT _ -> 134 | GREATER -> 133 | ...
module MenhirInterpreter = struct module ET = CamlinternalMenhirLib . TableInterpreter . MakeEngineTable ( Tables ) module TI = CamlinternalMenhirLib . Engine . Make ( ET ) include TI end
let flambda_unit = fun lexer lexbuf -> ( Obj . magic ( MenhirInterpreter . entry ` Legacy 525 lexer lexbuf ) : ( ( Fexpr . flambda_unit ) ) ) fun lexer lexbuf -> ( Obj . magic ( MenhirInterpreter . entry ` Legacy 0 lexer lexbuf ) : ( ( Fexpr . expect_test_spec ) ) ) ...
module Incremental = struct let flambda_unit = fun initial_position -> ( Obj . magic ( MenhirInterpreter . start 525 initial_position ) : ( ( Fexpr . flambda_unit ) ) MenhirInterpreter . checkpoint ) and expect_test_spec = fun initial_position -> ( Obj . magic ( MenhirInterpreter . ...
let message s = match s with | 0 -> " Expected an identifier for a continuation . \ n " | 3 -> " Expected either * followed by an identifier for an exception \ continuation , or \ n \ an expression . \ n " | 232 -> " Expected end of file . \ n " | 157 | 168 -> " Expected an i...
type classification_for_printing = | Constructive | Destructive | Neither
module Block_of_values_field = struct type t = | Any_value | Immediate | Boxed_float | Boxed_int32 | Boxed_int64 | Boxed_nativeint let [ @ ocamlformat " disable " ] print ppf t = match t with | Any_value -> Format . fprintf ppf " Any_value " | Immediate -> Format . fprintf ppf " Immediat...
module Block_kind = struct type t = | Values of Tag . Scannable . t * Block_of_values_field . t list | Naked_floats let [ @ ocamlformat " disable " ] print ppf t = match t with | Values ( tag , shape ) -> Format . fprintf ppf " [ @< hov 1 ( > Values @ \ [ @< hov 1 ( > ta...
module Array_kind = struct type t = | Immediates | Values | Naked_floats let [ @ ocamlformat " disable " ] print ppf t = match t with | Immediates -> Format . pp_print_string ppf " Immediates " | Naked_floats -> Format . pp_print_string ppf " Naked_floats " | Values -> Format . pp_pri...
module Duplicate_block_kind = struct type t = | Values of { tag : Tag . Scannable . t ; length : Targetint_31_63 . Imm . t } | Naked_floats of { length : Targetint_31_63 . Imm . t } let [ @ ocamlformat " disable " ] print ppf t = match t with | Values { tag ; length ; } ...
module Duplicate_array_kind = struct type t = | Immediates | Values | Naked_floats of { length : Targetint_31_63 . Imm . t option } let [ @ ocamlformat " disable " ] print ppf t = match t with | Immediates -> Format . pp_print_string ppf " Immediates " | Values -> Format . pp_print_s...
module Block_access_field_kind = struct type t = | Any_value | Immediate let [ @ ocamlformat " disable " ] print ppf t = match t with | Any_value -> Format . pp_print_string ppf " Any_value " | Immediate -> Format . pp_print_string ppf " Immediate " let compare = Stdlib . compare end
module Block_access_kind = struct type t = | Values of { tag : Tag . Scannable . t Or_unknown . t ; size : Targetint_31_63 . Imm . t Or_unknown . t ; field_kind : Block_access_field_kind . t } | Naked_floats of { size : Targetint_31_63 . Imm . t Or_unknown . t } let [ @ ocamlf...
type string_or_bytes = | String | Bytes
module Init_or_assign = struct type t = | Initialization | Assignment of Alloc_mode . t let [ @ ocamlformat " disable " ] print ppf t = let fprintf = Format . fprintf in match t with | Initialization -> fprintf ppf " Init " | Assignment mode -> fprintf ppf " Assign % a " Alloc_mode . p...
type array_like_operation = | Reading | Writing
let effects_of_operation operation = match operation with | Reading -> Effects . No_effects | Writing -> Effects . Arbitrary_effects
let reading_from_a_block mutable_or_immutable = let effects = effects_of_operation Reading in let coeffects = match ( mutable_or_immutable : Mutability . t ) with | Immutable | Immutable_unique -> Coeffects . No_coeffects | Mutable -> Coeffects . Has_coeffects in effects , coeffects
let reading_from_an_array ( array_kind : Array_kind . t ) ( mutable_or_immutable : Mutability . t ) = let effects : Effects . t = match array_kind with Immediates | Values | Naked_floats -> No_effects in let coeffects = match mutable_or_immutable with | Immutable | Immutable_unique -> Coeffect...
let reading_from_a_string_or_bigstring mutable_or_immutable = reading_from_a_block mutable_or_immutable
let writing_to_a_block = let effects = effects_of_operation Writing in effects , Coeffects . No_coeffects
type ' op comparison_behaviour = | Yielding_bool of ' op | Yielding_int_like_compare_functions
type comparison = | Eq | Neq | Lt | Gt | Le | Ge
let print_comparison ppf c = let fprintf = Format . fprintf in match c with | Neq -> fprintf ppf " " <> | Eq -> fprintf ppf " " = | Lt -> fprintf ppf " " < | Le -> fprintf ppf " " <= | Gt -> fprintf ppf " " > | Ge -> fprintf ppf " " >=
let print_comparison_and_behaviour ppf behaviour = match behaviour with | Yielding_bool op -> print_comparison ppf op | Yielding_int_like_compare_functions -> Format . pp_print_string ppf " < compare " >
type signed_or_unsigned = | Signed | Unsigned
type ordered_comparison = | Lt | Gt | Le | Ge
let print_ordered_comparison ppf signedness c = let fprintf = Format . fprintf in match signedness with | Unsigned -> begin match c with | Lt -> fprintf ppf " < u " | Le -> fprintf ppf " <= u " | Gt -> fprintf ppf " > u " | Ge -> fprintf ppf " >= u " end | Signed -> begin match c wit...
let print_ordered_comparison_and_behaviour ppf signedness behaviour = match behaviour with | Yielding_bool op -> print_ordered_comparison ppf signedness op | Yielding_int_like_compare_functions -> let signedness = match signedness with Signed -> " signed " | Unsigned -> " unsigned " in Format . fprin...
type equality_comparison = | Eq | Neq
let print_equality_comparison ppf op = match op with | Eq -> Format . pp_print_string ppf " Eq " | Neq -> Format . pp_print_string ppf " Neq "
type bigarray_kind = | Float32 | Float64 | Sint8 | Uint8 | Sint16 | Uint16 | Int32 | Int64 | Int_width_int | Targetint_width_int | Complex32 | Complex64
let element_kind_of_bigarray_kind k = match k with | Float32 | Float64 -> K . naked_float | Sint8 | Uint8 | Sint16 | Uint16 -> K . naked_immediate | Int32 -> K . naked_int32 | Int64 -> K . naked_int64 | Int_width_int -> K . naked_immediate | Targetint_width_int -> K . naked_nativeint | Com...
let print_bigarray_kind ppf k = let fprintf = Format . fprintf in match k with | Float32 -> fprintf ppf " Float32 " | Float64 -> fprintf ppf " Float64 " | Sint8 -> fprintf ppf " Sint8 " | Uint8 -> fprintf ppf " Uint8 " | Sint16 -> fprintf ppf " Sint16 " | Uint16 -> fprintf ppf " Ui...
let bigarray_kind_from_lambda ( kind : Lambda . bigarray_kind ) = match kind with | Pbigarray_unknown -> None | Pbigarray_float32 -> Some Float32 | Pbigarray_float64 -> Some Float64 | Pbigarray_sint8 -> Some Sint8 | Pbigarray_uint8 -> Some Uint8 | Pbigarray_sint16 -> Some Sint16 | Pbigarray_uint16 ...
type bigarray_layout = | C | Fortran
let print_bigarray_layout ppf l = let fprintf = Format . fprintf in match l with C -> fprintf ppf " C " | Fortran -> fprintf ppf " Fortran "
let bigarray_layout_from_lambda ( layout : Lambda . bigarray_layout ) = match layout with | Pbigarray_unknown_layout -> None | Pbigarray_c_layout -> Some C | Pbigarray_fortran_layout -> Some Fortran
let reading_from_a_bigarray kind = match ( kind : bigarray_kind ) with | Complex32 | Complex64 -> Effects . Only_generative_effects Immutable , Coeffects . Has_coeffects | Float32 | Float64 | Sint8 | Uint8 | Sint16 | Uint16 | Int32 | Int64 | Int_width_int | Targetint_width_int -> Effects . N...
let writing_to_a_bigarray kind = match ( kind : bigarray_kind ) with | Float32 | Float64 | Sint8 | Uint8 | Sint16 | Uint16 | Int32 | Int64 | Int_width_int | Targetint_width_int | Complex32 | Complex64 -> Effects . Arbitrary_effects , Coeffects . No_coeffects