text
stringlengths
12
786k
type string_like_value = | String | Bytes | Bigstring
let print_string_like_value ppf s = match s with | String -> Format . pp_print_string ppf " string " | Bytes -> Format . pp_print_string ppf " bytes " | Bigstring -> Format . pp_print_string ppf " bigstring "
type bytes_like_value = | Bytes | Bigstring
let print_bytes_like_value ppf b = match b with | Bytes -> Format . pp_print_string ppf " bytes " | Bigstring -> Format . pp_print_string ppf " bigstring "
type string_accessor_width = | Eight | Sixteen | Thirty_two | Sixty_four
let print_string_accessor_width ppf w = let fprintf = Format . fprintf in match w with | Eight -> fprintf ppf " 8 " | Sixteen -> fprintf ppf " 16 " | Thirty_two -> fprintf ppf " 32 " | Sixty_four -> fprintf ppf " 64 "
let byte_width_of_string_accessor_width width = match width with | Eight -> 1 | Sixteen -> 2 | Thirty_two -> 4 | Sixty_four -> 8
let kind_of_string_accessor_width width = match width with | Eight | Sixteen -> K . value | Thirty_two -> K . naked_int32 | Sixty_four -> K . naked_int64
let print_num_dimensions ppf d = Format . fprintf ppf " % d " d
type unary_int_arith_op = | Neg | Swap_byte_endianness
let print_unary_int_arith_op ppf o = let fprintf = Format . fprintf in match o with | Neg -> fprintf ppf " " ~- | Swap_byte_endianness -> fprintf ppf " bswap "
type unary_float_arith_op = | Abs | Neg
let print_unary_float_arith_op ppf o = let fprintf = Format . fprintf in match o with Abs -> fprintf ppf " abs " | Neg -> fprintf ppf " " ~-
type arg_kinds = | Variadic of K . t list | Variadic_all_of_kind of K . t
type result_kind = | Singleton of K . t | Unit
type nullary_primitive = | Optimised_out of K . t | Probe_is_enabled of { name : string } | Begin_region
let nullary_primitive_eligible_for_cse = function | Optimised_out _ | Probe_is_enabled _ | Begin_region -> false
let compare_nullary_primitive p1 p2 = match p1 , p2 with | Optimised_out k1 , Optimised_out k2 -> K . compare k1 k2 | Probe_is_enabled { name = name1 } , Probe_is_enabled { name = name2 } -> String . compare name1 name2 | Begin_region , Begin_region -> 0 | Optimised_out _ , ( Probe_i...
let equal_nullary_primitive p1 p2 = compare_nullary_primitive p1 p2 = 0
let print_nullary_primitive ppf p = match p with | Optimised_out _ -> Format . fprintf ppf " @< 0 >% sOptimised_out @< 0 >% s " ( Flambda_colours . elide ( ) ) ( Flambda_colours . normal ( ) ) | Probe_is_enabled { name } -> Format . fprintf ppf " [ @< hov 1 ( > Probe...
let result_kind_of_nullary_primitive p : result_kind = match p with | Optimised_out k -> Singleton k | Probe_is_enabled _ -> Singleton K . naked_immediate | Begin_region -> Singleton K . region
let effects_and_coeffects_of_nullary_primitive p = match p with | Optimised_out _ -> Effects . No_effects , Coeffects . No_coeffects | Probe_is_enabled _ -> Effects . Arbitrary_effects , Coeffects . Has_coeffects | Begin_region -> Effects . Arbitrary_effects , Coeffects . Has_coeffects
let nullary_classify_for_printing p = match p with Optimised_out _ | Probe_is_enabled _ | Begin_region -> Neither
type unary_primitive = | Duplicate_block of { kind : Duplicate_block_kind . t ; source_mutability : Mutability . t ; destination_mutability : Mutability . t } | Duplicate_array of { kind : Duplicate_array_kind . t ; source_mutability : Mutability . t ; destination_mutability : Mutabilit...
let unary_primitive_eligible_for_cse p ~ arg = match p with | Duplicate_array { kind = _ ; source_mutability = Immutable ; destination_mutability = Immutable } | Duplicate_block { kind = _ ; source_mutability = Immutable ; destination_mutability = Immutable } -> true | Duplicate_array _ ...
let compare_unary_primitive p1 p2 = let unary_primitive_numbering p = match p with | Duplicate_array _ -> 0 | Duplicate_block _ -> 1 | Is_int -> 2 | Get_tag -> 3 | Array_length -> 4 | Bigarray_length _ -> 5 | String_length _ -> 6 | Int_as_pointer -> 7 | Opaque_identity -> 8 | Int_arith...
let equal_unary_primitive p1 p2 = compare_unary_primitive p1 p2 = 0
let print_unary_primitive ppf p = let fprintf = Format . fprintf in match p with | Duplicate_block { kind ; source_mutability ; destination_mutability } -> fprintf ppf " [ @< hov 1 ( > Duplicate_block % a ( source % a ) ( dest % a ) ) ] " @ Duplicate_block_kind . print kind Mu...
let arg_kind_of_unary_primitive p = match p with | Duplicate_array _ | Duplicate_block _ -> K . value | Is_int -> K . value | Get_tag -> K . value | String_length _ -> K . value | Int_as_pointer -> K . value | Opaque_identity -> K . value | Int_arith ( kind , _ ) -> K . Standard_...
let result_kind_of_unary_primitive p : result_kind = match p with | Duplicate_array _ | Duplicate_block _ -> Singleton K . value | Is_int | Get_tag -> Singleton K . naked_immediate | String_length _ -> Singleton K . naked_immediate | Int_as_pointer -> Singleton K . value | Opaque_identity -> Si...
let effects_and_coeffects_of_unary_primitive p = match p with | Duplicate_array { kind = _ ; source_mutability ; destination_mutability ; _ } | Duplicate_block { kind = _ ; source_mutability ; destination_mutability ; _ } -> begin match source_mutability with | Immutable -> ( Effects ....
let unary_classify_for_printing p = match p with | Duplicate_array _ | Duplicate_block _ -> Constructive | String_length _ | Get_tag -> Destructive | Is_int | Int_as_pointer | Opaque_identity | Int_arith _ | Num_conv _ | Boolean_not | Reinterpret_int64_as_float | Float_arith _ -> Neither | Array_...
type binary_int_arith_op = | Add | Sub | Mul | Div | Mod | And | Or | Xor
let print_binary_int_arith_op ppf o = let fprintf = Format . fprintf in match o with | Add -> fprintf ppf " " + | Sub -> fprintf ppf " " - | Mul -> fprintf ppf " " * | Div -> fprintf ppf " " / | Mod -> fprintf ppf " mod " | And -> fprintf ppf " and " | Or -> fprintf ppf " ...
type int_shift_op = | Lsl | Lsr | Asr
let print_int_shift_op ppf o = let fprintf = Format . fprintf in match o with | Lsl -> fprintf ppf " lsl " | Lsr -> fprintf ppf " lsr " | Asr -> fprintf ppf " asr "
type binary_float_arith_op = | Add | Sub | Mul | Div
let print_binary_float_arith_op ppf o = let fprintf = Format . fprintf in match o with | Add -> fprintf ppf " . " + | Sub -> fprintf ppf " . " - | Mul -> fprintf ppf " . " * | Div -> fprintf ppf " . " /
type binary_primitive = | Block_load of Block_access_kind . t * Mutability . t | Array_load of Array_kind . t * Mutability . t | String_or_bigstring_load of string_like_value * string_accessor_width | Bigarray_load of num_dimensions * bigarray_kind * bigarray_layout | Phys_equal of Flambda_kind . t...
let binary_primitive_eligible_for_cse p = match p with | Array_load _ | Block_load _ -> false | String_or_bigstring_load _ -> false | Bigarray_load _ -> false | Phys_equal _ | Int_arith _ | Int_shift _ | Int_comp _ -> true | Float_arith _ | Float_comp _ -> Flambda_features . float_const_prop...
let compare_binary_primitive p1 p2 = let binary_primitive_numbering p = match p with | Array_load _ -> 0 | Block_load _ -> 1 | String_or_bigstring_load _ -> 2 | Bigarray_load _ -> 3 | Phys_equal _ -> 4 | Int_arith _ -> 5 | Int_shift _ -> 6 | Int_comp _ -> 7 | Float_arith _ -> 8 | ...
let equal_binary_primitive p1 p2 = compare_binary_primitive p1 p2 = 0
let print_binary_primitive ppf p = let fprintf = Format . fprintf in match p with | Block_load ( kind , mut ) -> fprintf ppf " [ ( @ Block_load @ % a @ % a ) ] " @ Block_access_kind . print kind Mutability . print mut | Array_load ( kind , mut ) -> fprintf ppf " [ ( @ Ar...
let args_kind_of_binary_primitive p = match p with | Block_load _ -> block_kind , block_index_kind | Array_load _ -> array_kind , array_index_kind | String_or_bigstring_load ( ( String | Bytes ) , _ ) -> string_or_bytes_kind , string_or_bigstring_index_kind | String_or_bigstring_load ( Big...
let result_kind_of_binary_primitive p : result_kind = match p with | Block_load ( block_access_kind , _ ) -> Singleton ( Block_access_kind . element_kind_for_load block_access_kind ) | Array_load ( kind , _ ) -> Singleton ( Array_kind . element_kind_for_load kind ) | String_or_bigstring...
let effects_and_coeffects_of_binary_primitive p = match p with | Block_load ( _ , mut ) -> reading_from_a_block mut | Array_load ( kind , mut ) -> reading_from_an_array kind mut | Bigarray_load ( _ , kind , _ ) -> reading_from_a_bigarray kind | String_or_bigstring_load ( String , _ )...
let binary_classify_for_printing p = match p with | Block_load _ | Array_load _ -> Destructive | Phys_equal _ | Int_arith _ | Int_shift _ | Int_comp _ | Float_arith _ | Float_comp _ | Bigarray_load _ | String_or_bigstring_load _ -> Neither
type ternary_primitive = | Block_set of Block_access_kind . t * Init_or_assign . t | Array_set of Array_kind . t * Init_or_assign . t | Bytes_or_bigstring_set of bytes_like_value * string_accessor_width | Bigarray_set of num_dimensions * bigarray_kind * bigarray_layout
let ternary_primitive_eligible_for_cse p = match p with | Block_set _ | Array_set _ | Bytes_or_bigstring_set _ | Bigarray_set _ -> false
let compare_ternary_primitive p1 p2 = let ternary_primitive_numbering p = match p with | Block_set _ -> 0 | Array_set _ -> 1 | Bytes_or_bigstring_set _ -> 2 | Bigarray_set _ -> 3 in match p1 , p2 with | Block_set ( kind1 , init_or_assign1 ) , Block_set ( kind2 , init_or_assign2 ) -> ...
let equal_ternary_primitive p1 p2 = compare_ternary_primitive p1 p2 = 0
let print_ternary_primitive ppf p = let fprintf = Format . fprintf in match p with | Block_set ( kind , init ) -> fprintf ppf " ( Block_set % a % a ) " Block_access_kind . print kind Init_or_assign . print init | Array_set ( kind , init ) -> fprintf ppf " ( Array_set % a % a ) ...
let args_kind_of_ternary_primitive p = match p with | Block_set ( access_kind , _ ) -> ( block_kind , block_index_kind , Block_access_kind . element_kind_for_set access_kind ) | Array_set ( kind , _ ) -> array_kind , array_index_kind , Array_kind . element_kind_for_set kind | Bytes_o...
let result_kind_of_ternary_primitive p : result_kind = match p with | Block_set _ | Array_set _ | Bytes_or_bigstring_set _ | Bigarray_set _ -> Unit
let effects_and_coeffects_of_ternary_primitive p = match p with | Block_set _ -> writing_to_a_block | Array_set _ -> writing_to_an_array | Bytes_or_bigstring_set _ -> writing_to_bytes_or_bigstring | Bigarray_set ( _ , kind , _ ) -> writing_to_a_bigarray kind
let ternary_classify_for_printing p = match p with | Block_set _ | Array_set _ | Bytes_or_bigstring_set _ | Bigarray_set _ -> Neither
type variadic_primitive = | Make_block of Block_kind . t * Mutability . t * Alloc_mode . t | Make_array of Array_kind . t * Mutability . t * Alloc_mode . t
let variadic_primitive_eligible_for_cse p ~ args = match p with | Make_block ( _ , _ , Local ) | Make_array ( _ , Immutable , Local ) -> false | Make_block ( _ , Immutable , _ ) | Make_array ( _ , Immutable , _ ) -> List . exists ( fun arg -> Simple . is_var arg ) ...
let compare_variadic_primitive p1 p2 = match p1 , p2 with | Make_block ( kind1 , mut1 , alloc_mode1 ) , Make_block ( kind2 , mut2 , alloc_mode2 ) -> let c = Block_kind . compare kind1 kind2 in if c <> 0 then c else let c = Stdlib . compare mut1 mut2 in if c <> 0 then c else Alloc_mode ....
let equal_variadic_primitive p1 p2 = compare_variadic_primitive p1 p2 = 0
let print_variadic_primitive ppf p = let fprintf = Format . fprintf in match p with | Make_block ( kind , mut , alloc_mode ) -> fprintf ppf " [ @< hov 1 ( > Make_block @ % a @ % a @ % a ) ] " @ Block_kind . print kind Mutability . print mut Alloc_mode . print alloc_mode | Make...
let args_kind_of_variadic_primitive p : arg_kinds = match p with | Make_block ( kind , _ , _ ) -> Variadic_all_of_kind ( Block_kind . element_kind kind ) | Make_array ( kind , _ , _ ) -> Variadic_all_of_kind ( Array_kind . element_kind_for_creation kind )
let result_kind_of_variadic_primitive p : result_kind = match p with Make_block _ | Make_array _ -> Singleton K . value
let effects_and_coeffects_of_variadic_primitive p ~ args = match p with | Make_block ( _ , mut , alloc_mode ) | Make_array ( _ , mut , alloc_mode ) -> let coeffects : Coeffects . t = match alloc_mode with | Heap -> Coeffects . No_coeffects | Local -> Coeffects . Has_coeffects in if Li...
let variadic_classify_for_printing p = match p with Make_block _ | Make_array _ -> Constructive
type t = | Nullary of nullary_primitive | Unary of unary_primitive * Simple . t | Binary of binary_primitive * Simple . t * Simple . t | Ternary of ternary_primitive * Simple . t * Simple . t * Simple . t | Variadic of variadic_primitive * Simple . t list
let classify_for_printing t = match t with | Nullary prim -> nullary_classify_for_printing prim | Unary ( prim , _ ) -> unary_classify_for_printing prim | Binary ( prim , _ , _ ) -> binary_classify_for_printing prim | Ternary ( prim , _ , _ , _ ) -> ternary_classify_for_printing p...
let equal t1 t2 = compare t1 t2 = 0
let free_names t = match t with | Nullary _ -> Name_occurrences . empty | Unary ( Project_function_slot { move_from ; move_to } , x0 ) -> Name_occurrences . add_function_slot_in_projection ( Name_occurrences . add_function_slot_in_projection ( Simple . free_names x0 ) move_to Name_mode ....
let apply_renaming t perm = let apply simple = Simple . apply_renaming simple perm in match t with | Nullary _ -> t | Unary ( prim , x0 ) -> Unary ( prim , apply x0 ) | Binary ( prim , x0 , x1 ) -> Binary ( prim , apply x0 , apply x1 ) | Ternary ( prim , x0 , x1 , x2 ) ...
let all_ids_for_export t = match t with | Nullary _ -> Ids_for_export . empty | Unary ( _prim , x0 ) -> Ids_for_export . from_simple x0 | Binary ( _prim , x0 , x1 ) -> Ids_for_export . add_simple ( Ids_for_export . from_simple x0 ) x1 | Ternary ( _prim , x0 , x1 , x2 ) -...
let args t = match t with | Nullary _ -> [ ] | Unary ( _ , x0 ) -> [ x0 ] | Binary ( _ , x0 , x1 ) -> [ x0 ; x1 ] | Ternary ( _ , x0 , x1 , x2 ) -> [ x0 ; x1 ; x2 ] | Variadic ( _ , xs ) -> xs
let result_kind ( t : t ) = match t with | Nullary prim -> result_kind_of_nullary_primitive prim | Unary ( prim , _ ) -> result_kind_of_unary_primitive prim | Binary ( prim , _ , _ ) -> result_kind_of_binary_primitive prim | Ternary ( prim , _ , _ , _ ) -> result_kind_of_tern...
let result_kind ' t = match result_kind t with Singleton kind -> kind | Unit -> K . value
let result_kind_of_nullary_primitive ' t = match result_kind_of_nullary_primitive t with | Singleton kind -> kind | Unit -> K . value
let result_kind_of_unary_primitive ' t = match result_kind_of_unary_primitive t with | Singleton kind -> kind | Unit -> K . value
let result_kind_of_binary_primitive ' t = match result_kind_of_binary_primitive t with | Singleton kind -> kind | Unit -> K . value
let result_kind_of_ternary_primitive ' t = match result_kind_of_ternary_primitive t with | Singleton kind -> kind | Unit -> K . value
let result_kind_of_variadic_primitive ' t = match result_kind_of_variadic_primitive t with | Singleton kind -> kind | Unit -> K . value
let effects_and_coeffects ( t : t ) = match t with | Nullary prim -> effects_and_coeffects_of_nullary_primitive prim | Unary ( prim , _ ) -> effects_and_coeffects_of_unary_primitive prim | Binary ( prim , _ , _ ) -> effects_and_coeffects_of_binary_primitive prim | Ternary ( prim , _ ,...
let no_effects_or_coeffects t = match effects_and_coeffects t with | No_effects , No_coeffects -> true | _ , _ -> false
let at_most_generative_effects t = match effects_and_coeffects t with | ( No_effects | Only_generative_effects _ ) , _ -> true | _ , _ -> false
let only_generative_effects t = match effects_and_coeffects t with | Only_generative_effects _ , _ -> true | _ , _ -> false
module Eligible_for_cse = struct type t = primitive_application let create ? map_arg t = let prim_eligible = match t with | Nullary prim -> nullary_primitive_eligible_for_cse prim | Unary ( prim , arg ) -> unary_primitive_eligible_for_cse prim ~ arg | Binary ( prim , _ , _ ) -> binary_primit...
let args t = match t with | Nullary _ -> [ ] | Unary ( _ , arg ) -> [ arg ] | Binary ( _ , arg1 , arg2 ) -> [ arg1 ; arg2 ] | Ternary ( _ , arg1 , arg2 , arg3 ) -> [ arg1 ; arg2 ; arg3 ] | Variadic ( _ , args ) -> args
module Without_args = struct type t = | Nullary of nullary_primitive | Unary of unary_primitive | Binary of binary_primitive | Ternary of ternary_primitive | Variadic of variadic_primitive let [ @ ocamlformat " disable " ] print ppf ( t : t ) = match t with | Nullary prim -> print_nullary_primit...
type ' a for_one_or_more_units = { fun_offset_table : int Closure_id . Map . t ; fv_offset_table : int Var_within_closure . Map . t ; constant_closures : Closure_id . Set . t ; closures : Closure_id . Set . t ; }
type t = { current_unit : Set_of_closures_id . t for_one_or_more_units ; imported_units : Simple_value_approx . function_declarations for_one_or_more_units ; ppf_dump : Format . formatter ; mutable constants_for_instrumentation : Clambda . ustructured_constant Symbol . Map . t ; }
let get_fun_offset t closure_id = let fun_offset_table = if Closure_id . in_compilation_unit closure_id ( Compilenv . current_unit ( ) ) then t . current_unit . fun_offset_table else t . imported_units . fun_offset_table in try Closure_id . Map . find closure_id fun_offset_table with Not_found...
let get_fv_offset t var_within_closure = let fv_offset_table = if Var_within_closure . in_compilation_unit var_within_closure ( Compilenv . current_unit ( ) ) then t . current_unit . fv_offset_table else t . imported_units . fv_offset_table in try Var_within_closure . Map . find var_within_clo...
let is_function_constant t closure_id = if Closure_id . Set . mem closure_id t . current_unit . closures then Closure_id . Set . mem closure_id t . current_unit . constant_closures else if Closure_id . Set . mem closure_id t . imported_units . closures then Closure_id . Set . mem closure_id...
let check_closure t ulam named : Clambda . ulambda = if not ! Clflags . clambda_checks then ulam else let desc = Primitive . simple ~ name " : caml_check_value_is_closure " ~ arity : 2 ~ alloc : false in let str = Format . asprintf " % a " Flambda . print_named named in let sym = Compile...
let clambda_arity ( func : Flambda . function_declaration ) : Clambda . arity = let nlocal = func . params |> List . filter ( fun p -> Lambda . is_local_mode ( Parameter . alloc_mode p ) ) |> List . length in Curried { nlocal } , Flambda_utils . function_arity func
let check_field t ulam pos named_opt : Clambda . ulambda = if not ! Clflags . clambda_checks then ulam else let desc = Primitive . simple ~ name " : caml_check_field_access " ~ arity : 3 ~ alloc : false in let str = match named_opt with | None -> " < none " > | Some named -> Format . a...
module Env : sig type t val empty : t val add_subst : t -> Variable . t -> Clambda . ulambda -> t val find_subst_exn : t -> Variable . t -> Clambda . ulambda val add_fresh_ident : t -> Variable . t -> V . t * t val ident_for_var_exn : t -> Variable . t -> V . t val add_fresh_mutable_iden...
let subst_var env var : Clambda . ulambda = try Env . find_subst_exn env var with Not_found -> try Uvar ( Env . ident_for_var_exn env var ) with Not_found -> Misc . fatal_errorf " Flambda_to_clambda : unbound variable % a . " @ Variable . print var
let subst_vars env vars = List . map ( subst_var env ) vars
let build_uoffset ulam offset : Clambda . ulambda = if offset = 0 then ulam else Uoffset ( ulam , offset )
let to_clambda_allocated_constant ( const : Allocated_const . t ) : Clambda . ustructured_constant = match const with | Float f -> Uconst_float f | Int32 i -> Uconst_int32 i | Int64 i -> Uconst_int64 i | Nativeint i -> Uconst_nativeint i | Immutable_string s | String s -> Uconst_string s | Immuta...
let to_uconst_symbol env symbol : Clambda . ustructured_constant option = match Env . allocated_const_for_symbol env symbol with | Some ( ( Float _ | Int32 _ | Int64 _ | Nativeint _ ) as const ) -> Some ( to_clambda_allocated_constant const ) | None | Some _ -> None