text
stringlengths
12
786k
let check_abbrev env sdecl ( id , decl ) = check_coherence env sdecl . ptype_loc ( Path . Pident id ) decl
let check_well_founded env loc path to_check ty = let visited = ref TypeMap . empty in let rec check ty0 parents ty = let ty = Btype . repr ty in if TypeSet . mem ty parents then begin if match ty0 . desc with | Tconstr ( p , _ , _ ) -> Path . same p path | _ -> false then raise ( Error (...
let check_well_founded_manifest env loc path decl = if decl . type_manifest = None then ( ) else let args = List . map ( fun _ -> Ctype . newvar ( ) ) decl . type_params in check_well_founded env loc path ( Path . same path ) ( Ctype . newconstr path args )
let check_well_founded_decl env loc path decl to_check = let open Btype in let it = { type_iterators with it_type_expr = ( fun _ -> check_well_founded env loc path to_check ) } in it . it_type_declaration it ( Ctype . generic_instance_declaration decl )
let check_recursion env loc path decl to_check = if decl . type_params = [ ] then ( ) else let visited = ref [ ] in let rec check_regular cpath args prev_exp ty = let ty = Ctype . repr ty in if not ( List . memq ty ! visited ) then begin visited := ty :: ! visited ; match ty . desc wi...
let check_abbrev_recursion env id_loc_list to_check tdecl = let decl = tdecl . typ_type in let id = tdecl . typ_id in check_recursion env ( List . assoc id id_loc_list ) ( Path . Pident id ) decl to_check
let check_duplicates sdecl_list = let labels = Hashtbl . create 7 and constrs = Hashtbl . create 7 in List . iter ( fun sdecl -> match sdecl . ptype_kind with Ptype_variant cl -> List . iter ( fun pcd -> try let name ' = Hashtbl . find constrs pcd . pcd_name . txt in Location . prerr_wa...
let name_recursion sdecl id decl = match decl with | { type_kind = Type_abstract ; type_manifest = Some ty ; type_private = Private ; } when is_fixed_type sdecl -> let ty = Ctype . repr ty in let ty ' = Btype . newty2 ty . level ty . desc in if Ctype . deep_occur ty ty ' then let td = T...
let name_recursion_decls sdecls decls = List . map2 ( fun sdecl ( id , decl ) -> ( id , name_recursion sdecl id decl ) ) sdecls decls
let check_redefined_unit ( td : Parsetree . type_declaration ) = let open Parsetree in let is_unit_constructor cd = cd . pcd_name . txt = " ( ) " in match td with | { ptype_name = { txt = name } ; ptype_manifest = None ; ptype_kind = Ptype_variant [ cd ] } when is_unit_constru...
let add_types_to_env decls env = List . fold_right ( fun ( id , decl ) env -> add_type ~ check : true id decl env ) decls env
let transl_type_decl env rec_flag sdecl_list = List . iter check_redefined_unit sdecl_list ; let fixed_types = List . filter is_fixed_type sdecl_list in let sdecl_list = List . map ( fun sdecl -> let ptype_name = let loc = { sdecl . ptype_name . loc with Location . loc_ghost = true } in mkloc...
let transl_extension_constructor env type_path type_params typext_params priv sext = let scope = Ctype . create_scope ( ) in let id = Ident . create_scoped ~ scope sext . pext_name . txt in let args , ret_type , kind = match sext . pext_kind with Pext_decl ( sargs , sret_type ) -> let targ...
let transl_extension_constructor env type_path type_params typext_params priv sext = Builtin_attributes . warning_scope sext . pext_attributes ( fun ( ) -> transl_extension_constructor env type_path type_params typext_params priv sext )
let transl_type_extension extend env loc styext = reset_type_variables ( ) ; Ctype . begin_def ( ) ; let type_path , type_decl = let lid = styext . ptyext_path in Env . lookup_type ~ loc : lid . loc lid . txt env in begin match type_decl . type_kind with | Type_open -> begin match type_...
let transl_type_extension extend env loc styext = Builtin_attributes . warning_scope styext . ptyext_attributes ( fun ( ) -> transl_type_extension extend env loc styext )
let transl_exception env sext = reset_type_variables ( ) ; Ctype . begin_def ( ) ; let ext = transl_extension_constructor env Predef . path_exn [ ] [ ] Asttypes . Public sext in Ctype . end_def ( ) ; Btype . iter_type_expr_cstr_args Ctype . generalize ext . ext_type . ext_arg...
let transl_type_exception env t = Builtin_attributes . check_no_alert t . ptyexn_attributes ; let contructor , newenv = Builtin_attributes . warning_scope t . ptyexn_attributes ( fun ( ) -> transl_exception env t . ptyexn_constructor ) in { tyexn_constructor = contructor ; tyexn_loc = t ....
type native_repr_attribute = | Native_repr_attr_absent | Native_repr_attr_present of native_repr_kind
let get_native_repr_attribute attrs ~ global_repr = match Attr_helper . get_no_payload_attribute [ " unboxed " ; " ocaml . unboxed " ] attrs , Attr_helper . get_no_payload_attribute [ " untagged " ; " ocaml . untagged " ] attrs , global_repr with | None , None , None -> N...
let native_repr_of_type env kind ty = match kind , ( Ctype . expand_head_opt env ty ) . desc with | Untagged , Tconstr ( path , _ , _ ) when Path . same path Predef . path_int -> Some Untagged_int | Unboxed , Tconstr ( path , _ , _ ) when Path . same path Predef . path_floa...
let error_if_has_deep_native_repr_attributes core_type = let open Ast_iterator in let this_iterator = { default_iterator with typ = fun iterator core_type -> begin match get_native_repr_attribute core_type . ptyp_attributes ~ global_repr : None with | Native_repr_attr_present kind -> raise ( Error ( cor...
let make_native_repr env core_type ty ~ global_repr = error_if_has_deep_native_repr_attributes core_type ; match get_native_repr_attribute core_type . ptyp_attributes ~ global_repr with | Native_repr_attr_absent -> Same_as_ocaml_repr | Native_repr_attr_present kind -> begin match native_repr_of_type env kind...
let rec parse_native_repr_attributes env core_type ty ~ global_repr = match core_type . ptyp_desc , ( Ctype . repr ty ) . desc , get_native_repr_attribute core_type . ptyp_attributes ~ global_repr : None with | Ptyp_arrow _ , Tarrow _ , Native_repr_attr_present kind -> raise ( Error ( co...
let check_unboxable env loc ty = let check_type acc ty : Path . Set . t = let ty = Ctype . repr ( Ctype . expand_head_opt env ty ) in try match ty . desc with | Tconstr ( p , _ , _ ) -> let tydecl = Env . find_type p env in if tydecl . type_unboxed . default then Path . Set . ad...
let transl_value_decl env loc valdecl = let cty = Typetexp . transl_type_scheme env valdecl . pval_type in let ty = cty . ctyp_type in let v = match valdecl . pval_prim with [ ] when Env . is_in_signature env -> { val_type = ty ; val_kind = Val_reg ; Types . val_loc = loc ; val_attribute...
let transl_value_decl env loc valdecl = Builtin_attributes . warning_scope valdecl . pval_attributes ( fun ( ) -> transl_value_decl env loc valdecl )
let transl_with_constraint env id row_path orig_decl sdecl = Env . mark_type_used ( Ident . name id ) orig_decl ; reset_type_variables ( ) ; Ctype . begin_def ( ) ; let tparams = make_params env sdecl . ptype_params in let params = List . map ( fun ( cty , _ ) -> cty . ctyp_ty...
let abstract_type_decl arity = let rec make_params n = if n <= 0 then [ ] else Ctype . newvar ( ) :: make_params ( n - 1 ) in Ctype . begin_def ( ) ; let decl = { type_params = make_params arity ; type_arity = arity ; type_kind = Type_abstract ; type_private = Public ; type_m...
let approx_type_decl sdecl_list = let scope = Ctype . create_scope ( ) in List . map ( fun sdecl -> ( Ident . create_scoped ~ scope sdecl . ptype_name . txt , abstract_type_decl ( List . length sdecl . ptype_params ) ) ) sdecl_list
let check_recmod_typedecl env loc recmod_ids path decl = let to_check path = Path . exists_free recmod_ids path in check_well_founded_decl env loc path decl to_check ; check_recursion env loc path decl to_check ; check_coherence env loc path decl
let explain_unbound_gen ppf tv tl typ kwd pr = try let ti = List . find ( fun ti -> Ctype . deep_occur tv ( typ ti ) ) tl in let ty0 = Btype . newgenty ( Tobject ( tv , ref None ) ) in Printtyp . reset_and_mark_loops_list [ typ ti ; ty0 ] ; fprintf ppf " . . [ @@< hov2 > ...
let explain_unbound ppf tv tl typ kwd lab = explain_unbound_gen ppf tv tl typ kwd ( fun ppf ti -> fprintf ppf " % s % a " ( lab ti ) Printtyp . marked_type_expr ( typ ti ) )
let explain_unbound_single ppf tv ty = let trivial ty = explain_unbound ppf tv [ ty ] ( fun t -> t ) " type " ( fun _ -> " " ) in match ( Ctype . repr ty ) . desc with Tobject ( fi , _ ) -> let ( tl , rv ) = Ctype . flatten_fields fi in if rv == tv then trivial ty else...
let tys_of_constr_args = function | Types . Cstr_tuple tl -> tl | Types . Cstr_record lbls -> List . map ( fun l -> l . Types . ld_type ) lbls
let report_error ppf = function | Repeated_parameter -> fprintf ppf " A type parameter occurs several times " | Duplicate_constructor s -> fprintf ppf " Two constructors are named % s " s | Too_many_constructors -> fprintf ppf " [ @ Too many non - constant constructors @ -- maximum is % i % s ...
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer ~ loc report_error err ) | _ -> None )
type error = Bad_immediacy_attribute of Type_immediacy . Violation . t
let compute_decl env tdecl = match ( tdecl . type_kind , tdecl . type_manifest ) with | ( Type_variant [ { cd_args = Cstr_tuple [ arg ] ; _ } ] , _ ) | ( Type_variant [ { cd_args = Cstr_record [ { ld_type = arg ; _ } ] ; _ } ] , _ ) | ( Type_record (...
let property : ( Type_immediacy . t , unit ) Typedecl_properties . property = let open Typedecl_properties in let eq = ( ) = in let merge ~ prop : _ ~ new_prop = new_prop in let default _decl = Type_immediacy . Unknown in let compute env decl ( ) = compute_decl env decl in let update_dec...
let update_decls env decls = Typedecl_properties . compute_property_noreq property env decls
type ( ' prop , ' req ) property = { eq : ' prop -> ' prop -> bool ; merge : prop ' : prop -> new_prop ' : prop -> ' prop ; default : decl -> ' prop ; compute : Env . t -> decl -> ' req -> ' prop ; update_decl : decl -> ' prop -> decl ; check : Env . t -> ...
let add_type ~ check id decl env = let open Types in Builtin_attributes . warning_scope ~ ppwarning : false decl . type_attributes ( fun ( ) -> Env . add_type ~ check id decl env )
let add_types_to_env decls env = List . fold_right ( fun ( id , decl ) env -> add_type ~ check : true id decl env ) decls env
let compute_property ( Ident . t * decl ) list -> ' req list -> ( Ident . t * decl ) list let props = List . map ( fun ( _id , decl ) -> property . default decl ) decls in let rec compute_fixpoint props = let new_decls = List . map2 ( fun ( id , decl ) prop -> ( id , ...
let compute_property_noreq property env decls = let req = List . map ( fun _ -> ( ) ) decls in compute_property property env decls req
type argument_to_unbox = { kind : parameter_kind ; mutability : Asttypes . mutable_flag ; argument_type : type_expr ; result_type_parameter_instances : type_expr list ; location : Location . t ; } | Record_field | Constructor_parameter | Constructor_field
type ' a multiplicity = | Zero | One of ' a | Several
type arity = argument_to_unbox multiplicity
type branching = arity multiplicity
type type_structure = | Synonym of type_expr | Abstract | Open | Algebraic of branching
let demultiply_list : type a b . a list -> ( a -> b ) -> b multiplicity = fun li f -> match li with | [ ] -> Zero | [ v ] -> One ( f v ) | _ :: _ :: _ -> Several
let structure : type_definition -> type_structure = fun def -> match def . type_kind with | Type_open -> Open | Type_abstract -> begin match def . type_manifest with | None -> Abstract | Some type_expr -> Synonym type_expr end | Type_record ( labels , _ ) -> Algebraic ( One ( demultiply_lis...
type error = | Non_separable_evar of string option
type mode = Sep . t = Ind | Sep | Deepsep
let compose : mode -> mode -> mode = fun m1 m2 -> match m1 with | Deepsep -> Deepsep | Sep -> m2 | Ind -> Ind
type type_var = { text : string option ; id : int ; }
module TVarMap = Map . Make ( struct type t = type_var let compare v1 v2 = compare v1 . id v2 . id end )
type context = mode TVarMap . t
let ( ) ++ = TVarMap . union ( fun _ m1 m2 -> Some ( max_mode m1 m2 ) )
let rec immediate_subtypes : type_expr -> type_expr list = fun ty -> match ( Ctype . repr ty ) . desc with | Tarrow ( _ , ty1 , ty2 , _ ) -> [ ty1 ; ty2 ] | Ttuple ( tys ) | Tpackage ( _ , _ , tys ) -> tys | Tobject ( row , class_ty ) -> let class_subtys = match...
let free_variables ty = Ctype . free_variables ( Ctype . repr ty ) |> List . map ( fun { desc ; id ; _ } -> match desc with | Tvar text -> { text ; id } | _ -> assert false )
type coinductive_hyps = { safe : ModeSet . t TypeMap . t ; unsafe : ModeSet . t TypeMap . t ; poison : ModeSet . t TypeMap . t ; }
module Hyps : sig type t = coinductive_hyps val empty : t val add : type_expr -> mode -> t -> t val guard : t -> t val poison : t -> t val safe : type_expr -> mode -> t -> bool val unsafe : type_expr -> mode -> t -> bool type t = coinductive_hyps let empty = { safe = TypeMap . empty ; unsafe...
let worst_case ty = let add ctx tvar = TVarMap . add tvar Deepsep ctx in List . fold_left add TVarMap . empty ( free_variables ty )
let check_type : Env . t -> type_expr -> mode -> context = fun env ty m -> let rec check_type hyps ty m = let ty = Ctype . repr ty in if Hyps . safe ty m hyps then empty else if Hyps . unsafe ty m hyps then worst_case ty else let hyps = Hyps . add ty m hyps in match ( ty . desc , m ) with | ...
let best_msig decl = List . map ( fun _ -> Ind ) decl . type_params
let worst_msig decl = List . map ( fun _ -> Deepsep ) decl . type_params
let msig_of_external_type decl = match decl . type_immediate with | Always | Always_on_64bits -> best_msig decl | Unknown -> worst_msig decl
let msig_of_context : decl_loc : Location . t -> parameters : type_expr list -> context -> Sep . signature = fun ~ decl_loc ~ parameters context -> let handle_equation ( acc , context ) param_instance = let param_instance = Ctype . repr param_instance in let get context var = try TVarMap . fi...
let check_def : Env . t -> type_definition -> Sep . signature = fun env def -> let boxed = not def . type_unboxed . unboxed in match structure def with | Abstract -> assert boxed ; msig_of_external_type def | Synonym type_expr -> check_type env type_expr Sep |> msig_of_context ~ decl_loc : def . ...
let compute_decl env decl = if Config . flat_float_array then check_def env decl else try check_def env decl with | Error _ -> best_msig decl
let property : ( prop , unit ) Typedecl_properties . property = let open Typedecl_properties in let eq ts1 ts2 = List . length ts1 = List . length ts2 && List . for_all2 Sep . eq ts1 ts2 in let merge ~ prop : _ ~ new_prop = new_prop in let default decl = best_msig decl in let compute env decl...
let update_decls env decls = Typedecl_properties . compute_property_noreq property env decls
type t = | Unavailable | This of type_expr | Only_on_64_bits of type_expr
let rec get_unboxed_type_representation env ty fuel = if fuel < 0 then Unavailable else let ty = Ctype . repr ( Ctype . expand_head_opt env ty ) in match ty . desc with | Tconstr ( p , args , _ ) -> begin match Env . find_type p env with | exception Not_found -> This ty | { type_immediat...
let get_unboxed_type_representation env ty = get_unboxed_type_representation env ty 100 ; ;
type surface_variance = bool * bool * bool
let get_variance ty visited = try TypeMap . find ty ! visited with Not_found -> Variance . null
let compute_variance env visited vari ty = let rec compute_variance_rec vari ty = let ty = Ctype . repr ty in let vari ' = get_variance ty visited in if Variance . subset vari vari ' then ( ) else let vari = Variance . union vari vari ' in visited := TypeMap . add ty vari ! visited ; let comp...
let make p n i = let open Variance in set May_pos p ( set May_neg n ( set May_weak n ( set Inj i null ) ) )
let compute_variance_type env ~ check ( required , loc ) decl tyl = let required = List . map ( fun ( c , n , i ) -> if c || n then ( c , n , i ) else ( true , true , i ) ) required in let params = List . map Btype . repr decl . type_params in let tvl = ref TypeMap . e...
let add_false = List . map ( fun ty -> false , ty )
let constrained vars ty = match ty . desc with | Tvar _ -> List . exists ( fun tl -> List . memq ty tl ) vars | _ -> true
let for_constr = function | Types . Cstr_tuple l -> add_false l | Types . Cstr_record l -> List . map ( fun { Types . ld_mutable ; ld_type } -> ( ld_mutable = Mutable , ld_type ) ) l
let compute_variance_gadt env ~ check ( required , loc as rloc ) decl ( tl , ret_type_opt ) = match ret_type_opt with | None -> compute_variance_type env ~ check rloc { decl with type_private = Private } ( for_constr tl ) | Some ret_type -> match Ctype . repr ret_type with | { desc = T...
let compute_variance_extension env ~ check decl ext rloc = compute_variance_gadt env ~ check rloc { decl with type_params = ext . ext_type_params } ( ext . ext_args , ext . ext_ret_type )
let compute_variance_decl env ~ check decl ( required , _ as rloc ) = if ( decl . type_kind = Type_abstract || decl . type_kind = Type_open ) && decl . type_manifest = None then List . map ( fun ( c , n , i ) -> make ( not n ) ( not c ) ( decl . type_kind <> Type_abstra...
let is_hash id = let s = Ident . name id in String . length s > 0 && s . [ 0 ] = ' ' #
let check_variance_extension env decl ext rloc = ignore ( compute_variance_extension env ~ check : true decl ext . Typedtree . ext_type rloc )
let compute_decl env ~ check decl req = compute_variance_decl env ~ check decl ( req , decl . type_loc )
let check_decl env decl req = ignore ( compute_variance_decl env ~ check : true decl ( req , decl . type_loc ) )
type prop = Variance . t list
type req = surface_variance list
let property : ( prop , req ) Typedecl_properties . property = let open Typedecl_properties in let eq li1 li2 = try List . for_all2 Variance . eq li1 li2 with _ -> false in let merge ~ prop ~ new_prop = List . map2 Variance . union prop new_prop in let default decl = List . map ( fun _ ->...
let transl_variance : Asttypes . variance -> _ = function | Covariant -> ( true , false , false ) | Contravariant -> ( false , true , false ) | Invariant -> ( false , false , false )
let variance_of_params ptype_params = List . map transl_variance ( List . map snd ptype_params )
let variance_of_sdecl sdecl = variance_of_params sdecl . Parsetree . ptype_params
let update_decls env sdecls decls = let required = List . map variance_of_sdecl sdecls in Typedecl_properties . compute_property property env decls required
let update_class_decls env cldecls = let decls , required = List . fold_right ( fun ( obj_id , obj_abbr , _cl_abbr , _clty , _cltydef , ci ) ( decls , req ) -> ( obj_id , obj_abbr ) :: decls , variance_of_params ci . Typedtree . ci_params :: req ) cldecls ( [ ] , ...