text stringlengths 0 601k |
|---|
let has_remove_aliases_attribute attr = let remove_aliases = Attr_helper . get_no_payload_attribute [ " remove_aliases " ; " ocaml . remove_aliases " ] attr in match remove_aliases with | None -> false | Some _ -> true |
let transl_modtype_longident loc env lid = let ( path , _info ) = Env . lookup_modtype ~ loc lid env in path |
let transl_module_alias loc env lid = Env . lookup_module_path ~ load : false ~ loc lid env |
let mkmty desc typ env loc attrs = let mty = { mty_desc = desc ; mty_type = typ ; mty_loc = loc ; mty_env = env ; mty_attributes = attrs ; } in Cmt_format . add_saved_type ( Cmt_format . Partial_module_type mty ) ; mty |
let mksig desc env loc = let sg = { sig_desc = desc ; sig_loc = loc ; sig_env = env } in Cmt_format . add_saved_type ( Cmt_format . Partial_signature_item sg ) ; sg |
let rec transl_modtype env smty = Builtin_attributes . warning_scope smty . pmty_attributes ( fun ( ) -> transl_modtype_aux env smty ) let mty = transl_modtype env sarg in { mty with mty_type = Mtype . scrape_for_functor_arg env mty . mty_type } let loc = smty . pmty_loc in match smty . pmty_desc with Pmty_ident lid ->... |
let rec path_of_module mexp = match mexp . mod_desc with | Tmod_ident ( p , _ ) -> p | Tmod_apply ( funct , arg , _coercion ) when ! Clflags . applicative_functors -> Papply ( path_of_module funct , path_of_module arg ) | Tmod_constraint ( mexp , _ , _ , _ ) -> path_of_module mexp | _ -> raise Not_a_path |
let path_of_module mexp = try Some ( path_of_module mexp ) with Not_a_path -> None |
let rec closed_modtype env = function Mty_ident _ -> true | Mty_alias _ -> true | Mty_signature sg -> let env = Env . add_signature sg env in List . for_all ( closed_signature_item env ) sg | Mty_functor ( arg_opt , body ) -> let env = match arg_opt with | Unit | Named ( None , _ ) -> env | Named ( Some id , param ) ->... |
let check_nongen_scheme env sig_item = match sig_item with Sig_value ( _id , vd , _ ) -> if not ( Ctype . closed_schema env vd . val_type ) then raise ( Error ( vd . val_loc , env , Non_generalizable vd . val_type ) ) | Sig_module ( _id , _ , md , _ , _ ) -> if not ( closed_modtype env md . md_type ) then raise ( Error... |
let check_nongen_schemes env sg = List . iter ( check_nongen_scheme env ) sg |
let anchor_submodule name anchor = match anchor , name with | None , _ | _ , None -> None | Some p , Some name -> Some ( Pdot ( p , name ) ) |
let anchor_recmodule = Option . map ( fun id -> Pident id ) |
let enrich_type_decls anchor decls oldenv newenv = match anchor with None -> newenv | Some p -> List . fold_left ( fun e info -> let id = info . typ_id in let info ' = Mtype . enrich_typedecl oldenv ( Pdot ( p , Ident . name id ) ) id info . typ_type in Env . add_type ~ check : true id info ' e ) oldenv decls |
let enrich_module_type anchor name mty env = match anchor , name with | None , _ | _ , None -> mty | Some p , Some name -> Mtype . enrich_modtype env ( Pdot ( p , name ) ) mty |
let check_recmodule_inclusion env bindings = let subst_and_strengthen env scope s id mty = let mty = Subst . modtype ( Rescope scope ) s mty in match id with | None -> mty | Some id -> Mtype . strengthen ~ aliasable : false env mty ( Subst . module_path s ( Pident id ) ) in let rec check_incl first_time n env s = let s... |
let rec package_constraints env loc mty constrs = if constrs = [ ] then mty else let sg = extract_sig env loc mty in let sg ' = List . map ( function | Sig_type ( id , ( { type_params [ ] } = as td ) , rs , priv ) when List . mem_assoc [ Ident . name id ] constrs -> let ty = List . assoc [ Ident . name id ] constrs in ... |
let modtype_of_package env loc p nl tl = match ( Env . find_modtype p env ) . mtd_type with | Some mty when nl <> [ ] -> package_constraints env loc mty ( List . combine ( List . map Longident . flatten nl ) tl ) | _ -> if nl = [ ] then Mty_ident p else raise ( Error ( loc , env , Signature_expected ) ) | exception Not... |
let package_subtype env p1 nl1 tl1 p2 nl2 tl2 = let mkmty p nl tl = let ntl = List . filter ( fun ( _n , t ) -> Ctype . free_variables t = [ ] ) ( List . combine nl tl ) in let ( nl , tl ) = List . split ntl in modtype_of_package env Location . none p nl tl in let mty1 = mkmty p1 nl1 tl1 and mty2 = mkmty p2 nl2 tl2 in ... |
let ( ) = Ctype . package_subtype := package_subtype |
let wrap_constraint env mark arg mty explicit = let mark = if mark then Includemod . Mark_both else Includemod . Mark_neither in let coercion = try Includemod . modtypes ~ loc : arg . mod_loc env ~ mark arg . mod_type mty with Includemod . Error msg -> raise ( Error ( arg . mod_loc , env , Not_included msg ) ) in { mod... |
let rec type_module ( ? alias = false ) sttn funct_body anchor env smod = Builtin_attributes . warning_scope smod . pmod_attributes ( fun ( ) -> type_module_aux ~ alias sttn funct_body anchor env smod ) match smod . pmod_desc with Pmod_ident lid -> let path = Env . lookup_module_path ~ load ( : not alias ) ~ loc : smod... |
let type_toplevel_phrase env s = Env . reset_required_globals ( ) ; let ( str , sg , to_remove_from_sg , env ) = type_structure ~ toplevel : true false None env s Location . none in ( str , sg , to_remove_from_sg , env ) |
let type_module_alias = type_module ~ alias : true true false None |
let type_module = type_module true false None |
let type_structure = type_structure false None |
let rec normalize_modtype env = function Mty_ident _ | Mty_alias _ -> ( ) | Mty_signature sg -> normalize_signature env sg | Mty_functor ( _param , body ) -> normalize_modtype env body Sig_value ( _id , desc , _ ) -> Ctype . normalize_type env desc . val_type | Sig_module ( _id , _ , md , _ , _ ) -> normalize_modtype e... |
let type_module_type_of env smod = let remove_aliases = has_remove_aliases_attribute smod . pmod_attributes in let tmty = match smod . pmod_desc with | Pmod_ident lid -> let path , md = Env . lookup_module ~ loc : smod . pmod_loc lid . txt env in rm { mod_desc = Tmod_ident ( path , lid ) ; mod_type = md . md_type ; mod... |
let rec extend_path path = fun lid -> match lid with | Lident name -> Pdot ( path , name ) | Ldot ( m , name ) -> Pdot ( extend_path path m , name ) | Lapply _ -> assert false |
let lookup_type_in_sig sg = let types , modules = List . fold_left ( fun acc item -> match item with | Sig_type ( id , _ , _ , _ ) -> let types , modules = acc in let types = String . Map . add ( Ident . name id ) id types in types , modules | Sig_module ( id , _ , _ , _ , _ ) -> let types , modules = acc in let module... |
let type_package env m p nl = Ctype . begin_def ( ) ; let context = Typetexp . narrow ( ) in let modl = type_module env m in let scope = Ctype . create_scope ( ) in Typetexp . widen context ; let nl ' , tl ' , env = match nl with | [ ] -> [ ] , [ ] , env | nl -> let type_path , env = match modl . mod_desc with | Tmod_i... |
let type_open_decl ? used_slot env od = type_open_decl ? used_slot ? toplevel : None false ( Signature_names . create ( ) ) env od |
let type_open_descr ? used_slot env od = type_open_descr ? used_slot ? toplevel : None env od |
let ( ) = Typecore . type_module := type_module_alias ; Typetexp . transl_modtype_longident := transl_modtype_longident ; Typetexp . transl_modtype := transl_modtype ; Typecore . type_open := type_open_ ? toplevel : None ; Typecore . type_open_decl := type_open_decl ; Typecore . type_package := type_package ; Typeclass... |
let type_implementation sourcefile outputprefix modulename initial_env ast = Cmt_format . clear ( ) ; Misc . try_finally ( fun ( ) -> Typecore . reset_delayed_checks ( ) ; Env . reset_required_globals ( ) ; if ! Clflags . print_types then Warnings . parse_options false " - 32 - 34 - 37 - 38 - 60 " ; let ( str , sg , na... |
let save_signature modname tsg outputprefix source_file initial_env cmi = Cmt_format . save_cmt ( outputprefix ^ " . cmti " ) modname ( Cmt_format . Interface tsg ) ( Some source_file ) initial_env ( Some cmi ) |
let type_interface env ast = transl_signature env ast |
let package_signatures units = let units_with_ids = List . map ( fun ( name , sg ) -> let oldid = Ident . create_persistent name in let newid = Ident . create_local name in ( oldid , newid , sg ) ) units in let subst = List . fold_left ( fun acc ( oldid , newid , _ ) -> Subst . add_module oldid ( Pident newid ) acc ) S... |
let package_units initial_env objfiles cmifile modulename = let units = List . map ( fun f -> let pref = chop_extensions f in let modname = String . capitalize_ascii ( Filename . basename pref ) in let sg = Env . read_signature modname ( pref ^ " . cmi " ) in if Filename . check_suffix f " . cmi " && not ( Mtype . no_c... |
let report_error ppf = function Cannot_apply mty -> fprintf ppf " [ @ This module is not a functor ; it has type @ % a ] " @ modtype mty | Not_included errs -> fprintf ppf " [ @< v > Signature mismatch :@ % a ] " @ Includemod . report_error errs | Cannot_eliminate_dependency mty -> fprintf ppf " [ @ This functor has ty... |
let report_error env ppf err = Printtyp . wrap_printing_env ~ error : true env ( fun ( ) -> report_error ppf err ) |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , env , err ) -> Some ( Location . error_of_printer ~ loc ( report_error env ) err ) | Error_forward err -> Some err | _ -> None ) |
let should_hide ( x : Typedtree . module_binding ) = match x . mb_attributes with | [ ] -> false | { attr_name = { txt = " internal . local " ; _ } ; _ } :: _ -> true | _ :: rest -> Ext_list . exists rest ( fun { attr_name = x ; _ } -> x . txt = " internal . local " ) |
let attrs : Parsetree . attributes = [ { attr_name = { txt = " internal . local " ; loc = Location . none } ; attr_payload = PStr [ ] ; attr_loc = Location . none ; } ; ] |
let no_type_defined ( x : Parsetree . structure_item ) = match x . pstr_desc with | Pstr_eval _ | Pstr_value _ | Pstr_primitive _ | Pstr_typext _ | Pstr_exception _ -> true | Pstr_include { pincl_mod = { pmod_desc = Pmod_constraint ( { pmod_desc = Pmod_structure [ { pstr_desc = Pstr_primitive _ } ] ; } , _ ) ; } ; } ->... |
let check ( x : Parsetree . structure ) = Ext_list . iter x ( fun x -> if not ( no_type_defined x ) then Location . raise_errorf ~ loc : x . pstr_loc " the structure is not supported in local extension " ) |
module List = struct include List let compare cmp a b = let rec loop a b = match a , b with | [ ] , [ ] -> 0 | [ ] , _ -> - 1 | _ , [ ] -> 1 | x :: xs , y :: ys -> let n = cmp x y in if n = 0 then loop xs ys else n in loop a b ; ; end |
module Uid : sig type t val compare : t -> t -> int val equal : t -> t -> bool val next : string -> t val hash : t -> int val name : t -> string val static : t type t = { code : int ; name : string } let compare a b = compare ( a . code : int ) b . code let equal a b = ( a . code : int ) = b . code let uid = ref 0 let ... |
module Key = struct type t = { uid : Uid . t ; params : t list } let rec compare k1 k2 = if k1 == k2 then 0 else ( let cmp = Uid . compare k1 . uid k2 . uid in if cmp <> 0 then cmp else List . compare compare k1 . params k2 . params ) ; ; let equal a b = compare a b = 0 let hash = ( Hashtbl . hash : t -> int ) let stat... |
type ' a t = Key . t |
type ' a typename = ' a t |
let key t = t |
let uid t = t . Key . uid |
let name t = Uid . name t . Key . uid |
let create ( ? name = " Typename . create " ) ( ) = { Key . uid = Uid . next name ; params = [ ] } let same ( type a b ) ( nm1 : a t ) ( nm2 : b t ) = Key . compare nm1 nm2 = 0 let same_witness ( type a b ) ( nm1 : a t ) ( nm2 : b t ) = if Key . compare nm1 nm2 = 0 then Some ( Obj . magic Type_equal . refl : ( a , b ) ... |
module type S0 = sig type t val typename_of_t : t typename end |
module type S1 = sig type ' a t val typename_of_t : ' a typename -> ' a t typename end |
module type S2 = sig type ( ' a , ' b ) t val typename_of_t : ' a typename -> ' b typename -> ( ' a , ' b ) t typename end |
module type S3 = sig type ( ' a , ' b , ' c ) t val typename_of_t : ' a typename -> ' b typename -> ' c typename -> ( ' a , ' b , ' c ) t typename end |
module type S4 = sig type ( ' a , ' b , ' c , ' d ) t val typename_of_t : ' a typename -> ' b typename -> ' c typename -> ' d typename -> ( ' a , ' b , ' c , ' d ) t typename end |
module type S5 = sig type ( ' a , ' b , ' c , ' d , ' e ) t val typename_of_t : ' a typename -> ' b typename -> ' c typename -> ' d typename -> ' e typename -> ( ' a , ' b , ' c , ' d , ' e ) t typename end |
module Make0 ( X : Named_intf . S0 ) = struct let uid = Uid . next X . name let typename_of_t = { Key . uid ; params = [ ] } end |
module Make1 ( X : Named_intf . S1 ) = struct let uid = Uid . next X . name let typename_of_t a = { Key . uid ; params = [ a ] } end |
module Make2 ( X : Named_intf . S2 ) = struct let uid = Uid . next X . name let typename_of_t a b = { Key . uid ; params = [ a ; b ] } end |
module Make3 ( X : Named_intf . S3 ) = struct let uid = Uid . next X . name let typename_of_t a b c = { Key . uid ; params = [ a ; b ; c ] } end |
module Make4 ( X : Named_intf . S4 ) = struct let uid = Uid . next X . name let typename_of_t a b c d = { Key . uid ; params = [ a ; b ; c ; d ] } end |
module Make5 ( X : Named_intf . S5 ) = struct let uid = Uid . next X . name let typename_of_t a b c d e = { Key . uid ; params = [ a ; b ; c ; d ; e ] } end |
module Key_table = Hashtbl . Make ( Key ) |
module Table ( X : sig type ' a t end ) = struct type data = Data : ' a t * ' a X . t -> data type t = data Key_table . t let create int = Key_table . create int let mem table name = Key_table . mem table ( key name ) let set table name data = Key_table . replace table ( key name ) ( Data ( name , data ) ) let find ( t... |
let fail uid_a uid_b = let msg = Printf . sprintf " Typename . Same_witness_exn % S % S " ( Uid . name uid_a ) ( Uid . name uid_b ) in failwith msg ; ; |
module Same_witness_exn_1 ( A : S1 ) ( B : S1 ) = struct type t = { eq : ' a . ( ' a A . t , ' a B . t ) Type_equal . t } let witness = let uid_a = uid ( A . typename_of_t static ) in let uid_b = uid ( B . typename_of_t static ) in if Uid . equal uid_a uid_b then { eq = Obj . magic Type_equal . refl } else fail uid_a u... |
module Same_witness_exn_2 ( A : S2 ) ( B : S2 ) = struct type t = { eq : ' a ' b . ( ( ' a , ' b ) A . t , ( ' a , ' b ) B . t ) Type_equal . t } let witness = let uid_a = uid ( A . typename_of_t static static ) in let uid_b = uid ( B . typename_of_t static static ) in if Uid . equal uid_a uid_b then { eq = Obj . magic... |
module Same_witness_exn_3 ( A : S3 ) ( B : S3 ) = struct type t = { eq : ' a ' b ' c . ( ( ' a , ' b , ' c ) A . t , ( ' a , ' b , ' c ) B . t ) Type_equal . t } let witness = let uid_a = uid ( A . typename_of_t static static static ) in let uid_b = uid ( B . typename_of_t static static static ) in if Uid . equal uid_a... |
module Same_witness_exn_4 ( A : S4 ) ( B : S4 ) = struct type t = { eq : ' a ' b ' c ' d . ( ( ' a , ' b , ' c , ' d ) A . t , ( ' a , ' b , ' c , ' d ) B . t ) Type_equal . t } let witness = let uid_a = uid ( A . typename_of_t static static static static ) in let uid_b = uid ( B . typename_of_t static static static st... |
module Same_witness_exn_5 ( A : S5 ) ( B : S5 ) = struct type t = { eq : ' a ' b ' c ' d ' e . ( ( ' a , ' b , ' c , ' d , ' e ) A . t , ( ' a , ' b , ' c , ' d , ' e ) B . t ) Type_equal . t } let witness = let uid_a = uid ( A . typename_of_t static static static static static ) in let uid_b = uid ( B . typename_of_t ... |
type t = { env : Env . t ; get_search_dirs : string -> string list } let from_summary ~ get_search_dirs summary subst = Persistent_env . get_search_dirs := get_search_dirs ; Envaux . reset_cache ( ) ; let env = Envaux . env_from_summary ( Obj . magic summary ) summary subst in { env ; get_search_dirs } let find_value p... |
type callable_and_self_argument = { callable : Type . Callable . t ; self_argument : Type . t option ; } |
module TypeOperation = struct module Compose = struct let apply_callable ~ signature_select input_annotation ~ callable_and_self { : callable ; self_argument } = match signature_select ~ arguments : [ { AttributeResolution . Argument . expression = None ; kind = Ast . Expression . Call . Argument . Positional ; resolve... |
let to_defined parameters = Type . Callable . Defined ( List . mapi ~ f ( : fun i element -> Type . Callable . Parameter . PositionalOnly { index = i ; annotation = element ; default = false } ) parameters ) |
let make_overload ~ parameters ~ return = Some { Type . Callable . annotation = return ; parameters = to_defined parameters } |
let test_compose_list _ = let assert_compose_list ( ? aliases = fun _ -> None ) ~ signature_select given expected = let parse source = Type . create ~ aliases ( : fun ? replace_unbound_parameters_with_any : _ -> aliases ) ( parse_single_expression ~ preprocess : true source ) in let merge_option_list = function | [ ] -... |
let ( ) = " typeOperation " >::: [ " compose_list " >:: test_compose_list ] |> Test . run |
let scrape_ty env ty = let ty = Ctype . expand_head_opt env ( Ctype . correct_levels ty ) in match ty . desc with | Tconstr ( p , _ , _ ) -> begin match Env . find_type p env with | { type_unboxed = { unboxed = true ; _ } ; _ } -> begin match Typedecl . get_unboxed_type_representation env ty with | None -> ty | Some ty... |
let scrape env ty = ( scrape_ty env ty ) . desc |
let is_function_type env ty = match scrape env ty with | Tarrow ( _ , lhs , rhs , _ ) -> Some ( lhs , rhs ) | _ -> None |
let is_base_type env ty base_ty_path = match scrape env ty with | Tconstr ( p , _ , _ ) -> Path . same p base_ty_path | _ -> false |
let maybe_pointer_type env ty = let ty = scrape_ty env ty in if Ctype . maybe_pointer_type env ty then Pointer else Immediate |
let maybe_pointer exp = maybe_pointer_type exp . exp_env exp . exp_type |
type classification = | Int | Float | Lazy | Addr | Any |
let classify env ty = let ty = scrape_ty env ty in if maybe_pointer_type env ty = Immediate then Int else match ty . desc with | Tvar _ | Tunivar _ -> Any | Tconstr ( p , _args , _abbrev ) -> if Path . same p Predef . path_float then Float else if Path . same p Predef . path_lazy_t then Lazy else if Path . same p Prede... |
let array_type_kind env ty = match scrape env ty with | Tconstr ( p , [ elt_ty ] , _ ) | Tpoly ( { desc = Tconstr ( p , [ elt_ty ] , _ ) } , _ ) when Path . same p Predef . path_array -> begin match classify env elt_ty with | Any -> if Config . flat_float_array then Pgenarray else Paddrarray | Float -> if Config . flat... |
let array_kind exp = array_type_kind exp . exp_env exp . exp_type |
let array_pattern_kind pat = array_type_kind pat . pat_env pat . pat_type |
let bigarray_decode_type env ty tbl dfl = match scrape env ty with | Tconstr ( Pdot ( Pident mod_id , type_name ) , [ ] , _ ) when Ident . name mod_id = " Stdlib__bigarray " -> begin try List . assoc type_name tbl with Not_found -> dfl end | _ -> dfl |
let kind_table = [ " float32_elt " , Pbigarray_float32 ; " float64_elt " , Pbigarray_float64 ; " int8_signed_elt " , Pbigarray_sint8 ; " int8_unsigned_elt " , Pbigarray_uint8 ; " int16_signed_elt " , Pbigarray_sint16 ; " int16_unsigned_elt " , Pbigarray_uint16 ; " int32_elt " , Pbigarray_int32 ; " int64_elt " , Pbigarr... |
let layout_table = [ " c_layout " , Pbigarray_c_layout ; " fortran_layout " , Pbigarray_fortran_layout ] |
let bigarray_type_kind_and_layout env typ = match scrape env typ with | Tconstr ( _p , [ _caml_type ; elt_type ; layout_type ] , _abbrev ) -> ( bigarray_decode_type env elt_type kind_table Pbigarray_unknown , bigarray_decode_type env layout_type layout_table Pbigarray_unknown_layout ) | _ -> ( Pbigarray_unknown , Pbiga... |
let value_kind env ty = match scrape env ty with | Tconstr ( p , _ , _ ) when Path . same p Predef . path_int -> Pintval | Tconstr ( p , _ , _ ) when Path . same p Predef . path_char -> Pintval | Tconstr ( p , _ , _ ) when Path . same p Predef . path_float -> Pfloatval | Tconstr ( p , _ , _ ) when Path . same p Predef ... |
let function_return_value_kind env ty = match is_function_type env ty with | Some ( _lhs , rhs ) -> value_kind env rhs | None -> Pgenval |
let lazy_val_requires_forward env ty = match classify env ty with | Any | Lazy -> true | Float -> Config . flat_float_array | Addr | Int -> false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.