text
stringlengths
0
601k
let statement_desc mapper = function | Tstmt_value ( p , e ) -> Tstmt_value ( mapper . pattern mapper p , mapper . expression mapper e ) | Tstmt_instance ( name , e ) -> Tstmt_instance ( ident mapper name , mapper . expression mapper e ) | Tstmt_type decl -> Tstmt_type ( mapper . type_decl mapper decl ) | Tstmt_convtyp...
let module_expr mapper { mod_desc ; mod_loc } = { mod_loc = mapper . location mapper mod_loc ; mod_desc = mapper . module_desc mapper mod_desc }
let module_desc mapper = function | Tmod_struct stmts -> Tmod_struct ( mapper . statements mapper stmts ) | Tmod_name name -> Tmod_name ( path mapper name ) | Tmod_functor ( name , fsig , me ) -> Tmod_functor ( str mapper name , mapper . module_sig mapper fsig , mapper . module_expr mapper me )
let location ( _mapper : mapper ) ( loc : Location . t ) = loc
let longident mapper = function | Longident . Lident str -> Longident . Lident str | Ldot ( l , str ) -> Ldot ( mapper . longident mapper l , str ) | Lapply ( l1 , l2 ) -> Lapply ( mapper . longident mapper l1 , mapper . longident mapper l2 )
let path mapper = function | Path . Pident ident -> Path . Pident ( mapper . ident mapper ident ) | Path . Pdot ( path , mode , str ) -> Path . Pdot ( mapper . path mapper path , mode , str ) | Path . Pocamldot ( path , mode , str , ocaml_name ) -> Path . Pocamldot ( mapper . path mapper path , mode , str , ocaml_name ...
let ident ( _mapper : mapper ) ( ident : Ident . t ) = ident
let default_iterator = { type_expr ; type_desc ; variant ; row_tag ; field_decl ; ctor_args ; ctor_decl ; type_decl ; type_decl_desc ; literal ; pattern ; pattern_desc ; expression ; expression_desc ; convert_body ; convert_body_desc ; convert ; convert_desc ; signature_item ; signature ; signature_desc ; module_sig ; ...
let test_check_typed_dictionaries context = let assert_test_typed_dictionary source = let mypy_extensions_stub = { handle = " mypy_extensions . pyi " ; source = { | import typing def TypedDict ( typename : str , fields : typing . Dict [ str , typing . Type [ _T ] ] , total : bool = . . . , ) -> typing . Type [ dict ] :...
let test_check_typed_dictionary_inference context = let assert_test_typed_dictionary source = let mypy_extensions_stub = { handle = " mypy_extensions . pyi " ; source = { | import typing def TypedDict ( typename : str , fields : typing . Dict [ str , typing . Type [ _T ] ] , total : bool = . . . , ) -> typing . Type [ ...
let test_check_typed_dictionary_inheritance context = let assert_test_typed_dictionary source = let mypy_extensions_stub = { handle = " mypy_extensions . pyi " ; source = { | import typing def TypedDict ( typename : str , fields : typing . Dict [ str , typing . Type [ _T ] ] , total : bool = . . . , ) -> typing . Type ...
let test_check_typed_dictionary_in_alias context = let assert_test_typed_dictionary source = let mypy_extensions_stub = { handle = " mypy_extensions . pyi " ; source = { | import typing def TypedDict ( typename : str , fields : typing . Dict [ str , typing . Type [ _T ] ] , total : bool = . . . , ) -> typing . Type [ d...
let test_check_optional_typed_dictionary context = assert_type_errors ~ context { | from typing import Any , TypedDict , Optional class MyDict ( TypedDict ) : a : str b : str def foo ( b : bool ) -> Optional [ MyDict ] : if b : return None return { " a " : str ( 1 ) , " b " : " hi " } def bar ( b : bool ) -> Optional [...
let ( ) = " typed_dictionary " >::: [ " check_typed_dictionaries " >:: test_check_typed_dictionaries ; " check_typed_dictionary_inference " >:: test_check_typed_dictionary_inference ; " check_typed_dictionary_inheritance " >:: test_check_typed_dictionary_inheritance ; " check_typed_dictionary_in_alias " >:: test_check_...
type native_repr_kind = Unboxed | Untagged
type error = Repeated_parameter | Duplicate_constructor of string | Too_many_constructors | Duplicate_label of string | Recursive_abbrev of string | Cycle_in_def of string * type_expr | Definition_mismatch of type_expr * Includecore . type_mismatch option | Constraint_failed of type_expr * type_expr | Inconsistent_cons...
let get_unboxed_from_attributes sdecl = let unboxed = Builtin_attributes . has_unboxed sdecl . ptype_attributes in let boxed = Builtin_attributes . has_boxed sdecl . ptype_attributes in match boxed , unboxed , ! Clflags . unboxed_types with | true , true , _ -> raise ( Error ( sdecl . ptype_loc , Boxed_and_unboxed ) ) ...
let add_type ~ check id decl env = Builtin_attributes . warning_scope ~ ppwarning : false decl . type_attributes ( fun ( ) -> Env . add_type ~ check id decl env )
let enter_type rec_flag env sdecl id = let needed = match rec_flag with | Asttypes . Nonrecursive -> begin match sdecl . ptype_kind with | Ptype_variant scds -> List . iter ( fun cd -> if cd . pcd_res <> None then raise ( Error ( cd . pcd_loc , Nonrec_gadt ) ) ) scds | _ -> ( ) end ; Btype . is_row_name ( Ident . name ...
let update_type temp_env env id loc = let path = Path . Pident id in let decl = Env . find_type path temp_env in match decl . type_manifest with None -> ( ) | Some ty -> let params = List . map ( fun _ -> Ctype . newvar ( ) ) decl . type_params in try Ctype . unify env ( Ctype . newconstr path params ) ty with Ctype . ...
let get_unboxed_type_representation env ty = match Typedecl_unboxed . get_unboxed_type_representation env ty with | Typedecl_unboxed . This x -> Some x | _ -> None
let is_float env ty = match get_unboxed_type_representation env ty with Some { desc = Tconstr ( p , _ , _ ) ; _ } -> Path . same p Predef . path_float | _ -> false
let is_fixed_type sd = let rec has_row_var sty = match sty . ptyp_desc with Ptyp_alias ( sty , _ ) -> has_row_var sty | Ptyp_class _ | Ptyp_object ( _ , Open ) | Ptyp_variant ( _ , Open , _ ) | Ptyp_variant ( _ , Closed , Some _ ) -> true | _ -> false in match sd . ptype_manifest with None -> false | Some sty -> sd . p...
let set_fixed_row env loc p decl = let tm = match decl . type_manifest with None -> assert false | Some t -> Ctype . expand_head env t in let rv = match tm . desc with Tvariant row -> let row = Btype . row_repr row in tm . desc <- Tvariant { row with row_fixed = Some Fixed_private } ; if Btype . static_row row then Bty...
let make_params env params = let make_param ( sty , v ) = try ( transl_type_param env sty , v ) with Already_bound -> raise ( Error ( sty . ptyp_loc , Repeated_parameter ) ) in List . map make_param params
let transl_labels env closed lbls = assert ( lbls <> [ ] ) ; let all_labels = ref String . Set . empty in List . iter ( fun { pld_name = { txt = name ; loc } } -> if String . Set . mem name ! all_labels then raise ( Error ( loc , Duplicate_label name ) ) ; all_labels := String . Set . add name ! all_labels ) lbls ; let...
let transl_constructor_arguments env closed = function | Pcstr_tuple l -> let l = List . map ( transl_simple_type env closed ) l in Types . Cstr_tuple ( List . map ( fun t -> t . ctyp_type ) l ) , Cstr_tuple l | Pcstr_record l -> let lbls , lbls ' = transl_labels env closed l in Types . Cstr_record lbls ' , Cstr_record...
let make_constructor env type_path type_params sargs sret_type = match sret_type with | None -> let args , targs = transl_constructor_arguments env true sargs in targs , None , args , None , type_params | Some sret_type -> let z = narrow ( ) in reset_type_variables ( ) ; let args , targs = transl_constructor_arguments ...
let check_type_var loc univ id = let f t = ( Btype . repr t ) . id = id in if not ( List . exists f univ ) then raise ( Error ( loc , Wrong_unboxed_type_float ) )
let rec check_unboxed_abstract_arg loc univ ty = match ty . desc with | Tvar _ -> check_type_var loc univ ty . id | Tarrow ( _ , t1 , t2 , _ ) | Tfield ( _ , _ , t1 , t2 ) -> check_unboxed_abstract_arg loc univ t1 ; check_unboxed_abstract_arg loc univ t2 | Ttuple args | Tconstr ( _ , args , _ ) | Tpackage ( _ , _ , arg...
let rec check_unboxed_gadt_arg loc univ env ty = match get_unboxed_type_representation env ty with | Some { desc = Tvar _ ; id } -> check_type_var loc univ id | Some { desc = Tarrow _ | Ttuple _ | Tpackage _ | Tobject _ | Tnil | Tvariant _ ; _ } -> ( ) | Some { desc = Tconstr ( p , args , _ ) ; _ } -> let tydecl = Env ...
let transl_declaration env sdecl id = reset_type_variables ( ) ; Ctype . begin_def ( ) ; let tparams = make_params env sdecl . ptype_params in let params = List . map ( fun ( cty , _ ) -> cty . ctyp_type ) tparams in let cstrs = List . map ( fun ( sty , sty ' , loc ) -> transl_simple_type env false sty , transl_simple_...
let generalize_decl decl = List . iter Ctype . generalize decl . type_params ; Btype . iter_type_expr_kind Ctype . generalize decl . type_kind ; begin match decl . type_manifest with | None -> ( ) | Some ty -> Ctype . generalize ty end
let rec check_constraints_rec env loc visited ty = let ty = Ctype . repr ty in if TypeSet . mem ty ! visited then ( ) else begin visited := TypeSet . add ty ! visited ; match ty . desc with | Tconstr ( path , args , _ ) -> let args ' = List . map ( fun _ -> Ctype . newvar ( ) ) args in let ty ' = Ctype . newconstr path...
let check_constraints_labels env visited l pl = let rec get_loc name = function [ ] -> assert false | pld :: tl -> if name = pld . pld_name . txt then pld . pld_type . ptyp_loc else get_loc name tl in List . iter ( fun { Types . ld_id = name ; ld_type = ty } -> check_constraints_rec env ( get_loc ( Ident . name name ) ...
let check_constraints env sdecl ( _ , decl ) = let visited = ref TypeSet . empty in begin match decl . type_kind with | Type_abstract -> ( ) | Type_variant l -> let find_pl = function Ptype_variant pl -> pl | Ptype_record _ | Ptype_abstract | Ptype_open -> assert false in let pl = find_pl sdecl . ptype_kind in let pl_i...
let check_coherence env loc dpath decl = match decl with { type_kind = ( Type_variant _ | Type_record _ | Type_open ) ; type_manifest = Some ty } -> begin match ( Ctype . repr ty ) . desc with Tconstr ( path , args , _ ) -> begin try let decl ' = Env . find_type path env in let err = if List . length args <> List . len...
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 ( loc , Recursive_abbrev ( Path ...
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 with | Tconstr ( path ' , args ' , _ ...
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_warning pcd . pcd_loc ( Warnings . ...
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 = Tconstr ( Path . Pident id , decl ...
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_constructor cd -> Location . prerr_warning td . pt...
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 ( sdecl . ptype_name . txt...
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 targs , tret_type , args , ret_typ...
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_decl . type_private with | Privat...
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_args ; Option . iter Ctype . generalize ext . e...
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 . ptyexn_loc ; tyexn_attributes ...
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 -> Native_repr_attr_absent | None , None , Some repr...
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_float -> Some Unboxed_float | Unboxed , Tconstr ( ...
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 ( core_type . ptyp_lo...
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 ty with | ...
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 ( core_type . ptyp_loc , Cannot_unbo...
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 . add p acc else acc | _ -> acc with Not_foun...
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_attributes = valdecl . pval_attributes } ...
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_type ) tparams in let orig_decl = Ctype . ins...
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_manifest = None ; type_variance = replicate_l...
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 > In % s @ % a ; @< 1 - 2 > the variable % a is un...
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 explain_unbound ppf tv tl ( fun ( _ , _ , t ) -> t...
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 ] " @ ( Config . max_tag +...
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 ( [ { ld_type = arg ; _ } ] , _ ) , _ ) when tdecl . type_unboxed . unb...
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_decl decl immediacy = { decl with t...
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 -> Ident . t -> decl -> ' req -> unit ; }
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 , property . update_decl decl prop ) ) decls props in ...
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_list labels @@ fun ld -> { locat...
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 ! class_ty with | None -> [ ] | Some ( _ , tys ) -> tys i...
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 ; }