text
stringlengths
12
786k
let to_symbol t = pattern_match t ~ var ( : fun _ -> None ) ~ symbol ( : fun symbol -> Some symbol )
let set_of_var_set vars = Variable . Set . fold ( fun v t_set -> Set . add ( var v ) t_set ) vars Set . empty
let set_of_symbol_set symbols = Symbol . Set . fold ( fun sym t_set -> Set . add ( symbol sym ) t_set ) symbols Set . empty
let set_to_symbol_set t = Set . fold ( fun name syms -> match to_symbol name with | None -> syms | Some sym -> Symbol . Set . add sym syms ) t Symbol . Set . empty
let compilation_unit t = pattern_match t ~ var ( : fun var -> Variable . compilation_unit var ) ~ symbol ( : fun sym -> Symbol . compilation_unit sym )
let is_imported t = let current = Compilation_unit . get_current_exn ( ) in not ( Compilation_unit . equal current ( compilation_unit t ) )
let must_be_var_opt t = pattern_match t ~ var ( : fun var -> Some var ) ~ symbol ( : fun _ -> None )
let must_be_symbol t = pattern_match t ~ var ( : fun _ -> Misc . fatal_errorf " Must be a symbol :@ % a " print t ) ~ symbol ( : fun sym -> sym )
let must_be_symbol_opt t = pattern_match t ~ var ( : fun _ -> None ) ~ symbol ( : fun sym -> Some sym )
module Pair = struct include Container_types . Make_pair ( Int_ids . Name ) ( Int_ids . Name ) type nonrec t = t * t end
let is_reserved = function | " and " | " as " | " assert " | " asr " | " begin " | " class " | " constraint " | " do " | " done " | " downto " | " else " | " end " | " exception " | " external " | " false " | " for " | " fun " | " ...
let to_snake_case ident = let to_list s = let r = ref [ ] in String . iter ~ f ( : fun c -> r := c :: ! r ) s ; List . rev ! r in let to_string l = let bytes = Bytes . create ( List . length l ) in List . iteri ~ f ( : fun i c -> Bytes . set bytes i c ) l ; Bytes . to_st...
let field_name ( ? mangle_f ( = fun x -> x ) ) field_name = match String . uncapitalize_ascii ( mangle_f field_name ) with | name when is_reserved name -> name ^ " ' " | name -> name
let module_name ( ? mangle_f ( = fun x -> x ) ) name = let name = mangle_f name in match name . [ 0 ] with | ' _ ' -> " P " ^ name | _ -> String . capitalize_ascii name
let poly_constructor_name ( ? mangle_f ( = fun x -> x ) ) name = " ` " ^ ( mangle_f name |> String . capitalize_ascii )
module type Term = sig type t val apply_renaming : t -> Renaming . t -> t include Contains_ids . S with type t := t end
type ( ' bindable , ' term ) t = ' bindable * ' term
module Make_matching_and_renaming0 ( Bindable : Bindable . S ) ( Term : sig type t val apply_renaming : t -> Renaming . t -> t end ) = struct let [ @ inline always ] pattern_match ( bindable , term ) ~ f = let fresh_bindable = Bindable . rename bindable in let perm = Bindable . rena...
module Make_ids_for_export0 ( Bindable : Bindable . S ) ( Term : Contains_ids . S ) = struct let all_ids_for_export ( bindable , term ) = Ids_for_export . union ( Bindable . all_ids_for_export bindable ) ( Term . all_ids_for_export term ) end
module Make ( Bindable : Bindable . S ) ( Term : Term ) = struct type nonrec t = ( Bindable . t , Term . t ) t let create bindable term = bindable , term include Make_matching_and_renaming0 ( Bindable ) ( Term ) include Make_ids_for_export0 ( Bindable ) ( Term ) end
module Make_free_names ( Bindable : Bindable . S ) ( Term : sig include Term val free_names : t -> Name_occurrences . t end ) = struct type nonrec t = ( Bindable . t , Term . t ) t let free_names ( bindable , term ) = Name_occurrences . diff ( Term . free_names term ) ( Bind...
module Make_matching_and_renaming ( Bindable : Bindable . S ) ( Term : sig type t val apply_renaming : t -> Renaming . t -> t end ) = struct type nonrec t = ( Bindable . t , Term . t ) t include Make_matching_and_renaming0 ( Bindable ) ( Term ) end
module Make_ids_for_export ( Bindable : Bindable . S ) ( Term : Contains_ids . S ) = struct type nonrec t = ( Bindable . t , Term . t ) t include Make_ids_for_export0 ( Bindable ) ( Term ) end
let peek_for_printing t = assert ( not ( Flambda_features . freshen_when_printing ( ) ) ) ; t
type t = | Normal | Phantom | In_types
let join_in_terms t1 t2 = match t1 , t2 with | Normal , Normal | Phantom , Phantom -> t1 | Normal , Phantom | Phantom , Normal -> Normal | In_types , _ | _ , In_types -> Misc . fatal_error " Cannot use [ join_in_terms ] with [ In_types ] mode "
let is_normal t = match t with Normal -> true | In_types | Phantom -> false
let is_phantom t = match t with Phantom -> true | In_types | Normal -> false
let is_in_types t = match t with In_types -> true | Normal | Phantom -> false
let can_be_in_terms t = match t with Normal | Phantom -> true | In_types -> false
let compare_partial_order t1 t2 = match t1 , t2 with | Normal , Normal | Phantom , Phantom | In_types , In_types -> Some 0 | Normal , ( Phantom | In_types ) -> Some 1 | ( Phantom | In_types ) , Normal -> Some ( - 1 ) | Phantom , In_types | In_types , Phantom -> None type no...
let compare _ _ = ` Be_explicit_about_total_or_partial_ordering
module Or_absent = struct type t = | Absent | Present of name_mode let absent = Absent let present name_mode = Present name_mode let is_present = function Absent -> false | Present _ -> true let is_present_as_normal = function | Absent -> false | Present Normal -> true | Present ( Phantom | In_types...
module For_one_variety_of_names ( N : sig include Container_types . S val apply_renaming : t -> Renaming . t -> t type t val print : Format . formatter -> t -> unit val equal : t -> t -> bool val empty : t val is_empty : t -> bool val singleton : N . t -> Name_mode . t -> t val add : t -> ...
module For_names = For_one_variety_of_names ( struct include Name let apply_renaming t perm = Renaming . apply_name perm t end )
module For_continuations = For_one_variety_of_names ( struct include Continuation let apply_renaming t perm = Renaming . apply_continuation perm t end )
module For_function_slots = For_one_variety_of_names ( struct include Function_slot let apply_renaming t _perm = t end )
module For_value_slots = For_one_variety_of_names ( struct include Value_slot let apply_renaming t _perm = t end )
module For_code_ids = For_one_variety_of_names ( struct include Code_id let apply_renaming t perm = Renaming . apply_code_id perm t end )
type t = { names : For_names . t ; continuations : For_continuations . t ; continuations_with_traps : For_continuations . t ; continuations_in_trap_actions : For_continuations . t ; function_slots_in_projections : For_function_slots . t ; value_slots_in_projections : For_value_slots . t ;...
let empty = { names = For_names . empty ; continuations = For_continuations . empty ; continuations_with_traps = For_continuations . empty ; continuations_in_trap_actions = For_continuations . empty ; function_slots_in_projections = For_function_slots . empty ; value_slots_in_projections = ...
let [ @ ocamlformat " disable " ] print ppf ( { names ; continuations ; continuations_with_traps ; continuations_in_trap_actions ; function_slots_in_projections ; value_slots_in_projections ; function_slots_in_declarations ; value_slots_in_declarations ; code_ids ; newer_version_of_code_i...
let singleton_continuation cont = { empty with continuations = For_continuations . singleton cont Name_mode . normal }
let singleton_continuation_in_trap_action cont = { empty with continuations_in_trap_actions = For_continuations . singleton cont Name_mode . normal }
let add_continuation t cont ~ has_traps = let continuations = For_continuations . add t . continuations cont Name_mode . normal in let continuations_with_traps = if has_traps then For_continuations . add t . continuations_with_traps cont Name_mode . normal else t . continuations_with_traps in { t wi...
let add_continuation_in_trap_action t cont = { t with continuations_in_trap_actions = For_continuations . add t . continuations_in_trap_actions cont Name_mode . normal }
let count_continuation t cont = For_continuations . count t . continuations cont
let continuation_is_applied_with_traps t cont = For_continuations . mem t . continuations_with_traps cont
let count_variable t var = For_names . count t . names ( Name . var var )
let count_variable_normal_mode t var = For_names . count_normal t . names ( Name . var var )
let singleton_variable var name_mode = { empty with names = For_names . singleton ( Name . var var ) name_mode }
let add_variable t var name_mode = { t with names = For_names . add t . names ( Name . var var ) name_mode }
let add_symbol t sym name_mode = { t with names = For_names . add t . names ( Name . symbol sym ) name_mode }
let add_name t name name_mode = { t with names = For_names . add t . names name name_mode }
let add_function_slot_in_projection t clos_id name_mode = { t with function_slots_in_projections = For_function_slots . add t . function_slots_in_projections clos_id name_mode }
let add_value_slot_in_projection t clos_var name_mode = { t with value_slots_in_projections = For_value_slots . add t . value_slots_in_projections clos_var name_mode }
let add_function_slot_in_declaration t clos_id name_mode = { t with function_slots_in_declarations = For_function_slots . add t . function_slots_in_declarations clos_id name_mode }
let add_value_slot_in_declaration t clos_var name_mode = { t with value_slots_in_declarations = For_value_slots . add t . value_slots_in_declarations clos_var name_mode }
let add_function_slot_in_types t clos_id = { t with function_slots_in_declarations = For_function_slots . add t . function_slots_in_declarations clos_id Name_mode . in_types ; function_slots_in_projections = For_function_slots . add t . function_slots_in_projections clos_id Name_mode . in_types }
let add_value_slot_in_types t clos_var = { t with value_slots_in_declarations = For_value_slots . add t . value_slots_in_declarations clos_var Name_mode . in_types ; value_slots_in_projections = For_value_slots . add t . value_slots_in_projections clos_var Name_mode . in_types }
let add_code_id t id name_mode = { t with code_ids = For_code_ids . add t . code_ids id name_mode }
let singleton_code_id id name_mode = add_code_id empty id name_mode
let add_newer_version_of_code_id t id name_mode = { t with newer_version_of_code_ids = For_code_ids . add t . newer_version_of_code_ids id name_mode }
let singleton_symbol sym name_mode = { empty with names = For_names . singleton ( Name . symbol sym ) name_mode }
let singleton_name name name_mode = { empty with names = For_names . singleton name name_mode }
let create_variables vars name_mode = let names = Variable . Set . fold ( fun var names -> For_names . add names ( Name . var var ) name_mode ) vars For_names . empty in { empty with names }
let create_variables ' name_mode vars = create_variables vars name_mode
let create_names names name_mode = let names = Name . Set . fold ( fun name names -> For_names . add names name name_mode ) names For_names . empty in { empty with names }
let binary_conjunction ~ for_names ~ for_continuations ~ for_function_slots ~ for_value_slots ~ for_code_ids { names = names1 ; continuations = continuations1 ; continuations_with_traps = continuations_with_traps1 ; continuations_in_trap_actions = continuations_in_trap_actions1 ; function_slots_in_pr...
let binary_disjunction ~ for_names ~ for_continuations ~ for_function_slots ~ for_value_slots ~ for_code_ids { names = names1 ; continuations = continuations1 ; continuations_with_traps = continuations_with_traps1 ; continuations_in_trap_actions = continuations_in_trap_actions1 ; function_slots_in_pr...
let binary_op ~ for_names ~ for_continuations ~ for_function_slots ~ for_value_slots ~ for_code_ids { names = names1 ; continuations = continuations1 ; continuations_with_traps = continuations_with_traps1 ; continuations_in_trap_actions = continuations_in_trap_actions1 ; function_slots_in_projections...
let diff { names = names1 ; continuations = continuations1 ; continuations_with_traps = continuations_with_traps1 ; continuations_in_trap_actions = continuations_in_trap_actions1 ; function_slots_in_projections = function_slots_in_projections1 ; value_slots_in_projections = value_slots_in_projections1...
let union t1 t2 = binary_op ~ for_names : For_names . union ~ for_continuations : For_continuations . union ~ for_function_slots : For_function_slots . union ~ for_value_slots : For_value_slots . union ~ for_code_ids : For_code_ids . union t1 t2
let equal t1 t2 = binary_conjunction ~ for_names : For_names . equal ~ for_continuations : For_continuations . equal ~ for_function_slots : For_function_slots . equal ~ for_value_slots : For_value_slots . equal ~ for_code_ids : For_code_ids . equal t1 t2
let is_empty t = equal t empty
let no_variables t = For_names . for_all t . names ~ f ( : fun var -> not ( Name . is_var var ) )
let no_continuations { names = _ ; continuations ; continuations_with_traps = _ ; continuations_in_trap_actions ; function_slots_in_projections = _ ; value_slots_in_projections = _ ; function_slots_in_declarations = _ ; value_slots_in_declarations = _ ; code_ids = _ ; newer_version_of_...
let subset_domain t1 t2 = binary_conjunction ~ for_names : For_names . subset_domain ~ for_continuations : For_continuations . subset_domain ~ for_function_slots : For_function_slots . subset_domain ~ for_value_slots : For_value_slots . subset_domain ~ for_code_ids : For_code_ids . subset_domain t1...
let inter_domain_is_non_empty t1 t2 = binary_disjunction ~ for_names : For_names . inter_domain_is_non_empty ~ for_continuations : For_continuations . inter_domain_is_non_empty ~ for_function_slots : For_function_slots . inter_domain_is_non_empty ~ for_value_slots : For_value_slots . inter_domain_is_no...
let rec union_list ts = match ts with [ ] -> empty | t :: ts -> union t ( union_list ts )
let function_slots_in_normal_projections t = For_function_slots . fold_with_mode t . function_slots_in_projections ~ init : Function_slot . Set . empty ~ f ( : fun acc function_slot name_mode -> if Name_mode . is_normal name_mode then Function_slot . Set . add function_slot acc else acc )
let all_function_slots t = Function_slot . Set . union ( For_function_slots . keys t . function_slots_in_projections ) ( For_function_slots . keys t . function_slots_in_declarations )
let value_slots_in_normal_projections t = For_value_slots . fold_with_mode t . value_slots_in_projections ~ init : Value_slot . Set . empty ~ f ( : fun acc value_slot name_mode -> if Name_mode . is_normal name_mode then Value_slot . Set . add value_slot acc else acc )
let all_value_slots t = Value_slot . Set . union ( For_value_slots . keys t . value_slots_in_projections ) ( For_value_slots . keys t . value_slots_in_declarations )
let symbols t = For_names . keys t . names |> Name . set_to_symbol_set
let continuations t = For_continuations . keys t . continuations
let continuations_with_traps t = For_continuations . keys t . continuations_with_traps
let continuations_including_in_trap_actions t = Continuation . Set . union ( For_continuations . keys t . continuations ) ( For_continuations . keys t . continuations_in_trap_actions )
let code_ids t = For_code_ids . keys t . code_ids
let newer_version_of_code_ids t = For_code_ids . keys t . newer_version_of_code_ids
let code_ids_and_newer_version_of_code_ids t = Code_id . Set . union ( code_ids t ) ( newer_version_of_code_ids t )
let only_newer_version_of_code_ids t = Code_id . Set . diff ( newer_version_of_code_ids t ) ( code_ids t )
let mem_name t name = For_names . mem t . names name
let mem_var t var = For_names . mem t . names ( Name . var var )
let mem_symbol t symbol = For_names . mem t . names ( Name . symbol symbol )
let mem_code_id t code_id = For_code_ids . mem t . code_ids code_id
let mem_newer_version_of_code_id t code_id = For_code_ids . mem t . newer_version_of_code_ids code_id
let mem_value_slot_in_projections t value_slot = For_value_slots . mem t . value_slots_in_projections value_slot
let value_slot_is_used_or_imported t value_slot = Value_slot . is_imported value_slot || For_value_slots . mem t . value_slots_in_projections value_slot
let remove_var t var = if For_names . is_empty t . names then t else let names = For_names . remove t . names ( Name . var var ) in { t with names }