text stringlengths 12 786k |
|---|
let extract_constraints cty = let sign = Ctype . signature_of_class_type cty in ( Vars . fold ( fun lab _ vars -> lab :: vars ) sign . csig_vars [ ] , begin let ( fields , _ ) = Ctype . flatten_fields ( Ctype . object_fields sign . csig_self ) in List . fold_left ( fun meths... |
let rec abbreviate_class_type path params cty = match cty with Cty_constr ( _ , _ , _ ) | Cty_signature _ -> Cty_constr ( path , params , cty ) | Cty_arrow ( l , ty , cty ) -> Cty_arrow ( l , ty , abbreviate_class_type path params cty ) |
let rec closed_class_type = function Cty_constr ( _ , params , _ ) -> List . for_all ( Ctype . closed_schema Env . empty ) params | Cty_signature sign -> Ctype . closed_schema Env . empty sign . csig_self && Vars . fold ( fun _ ( _ , _ , ty ) cc -> Ctype . closed_schema ... |
let closed_class cty = List . for_all ( Ctype . closed_schema Env . empty ) cty . cty_params && closed_class_type cty . cty_type |
let rec limited_generalize rv = function Cty_constr ( _path , params , cty ) -> List . iter ( Ctype . limited_generalize rv ) params ; limited_generalize rv cty | Cty_signature sign -> Ctype . limited_generalize rv sign . csig_self ; Vars . iter ( fun _ ( _ , _ , ty ) -> Cty... |
let rc node = Cmt_format . add_saved_type ( Cmt_format . Partial_class_expr node ) ; Stypes . record ( Stypes . Ti_class node ) ; node |
let enter_met_env ? check loc lab kind unbound_kind ty val_env met_env par_env = let val_env = Env . enter_unbound_value lab unbound_kind val_env in let par_env = Env . enter_unbound_value lab unbound_kind par_env in let ( id , met_env ) = Env . enter_value ? check lab { val_type = ty ; val_kind ... |
let enter_val cl_num vars inh lab mut virt ty val_env met_env par_env loc = let ( id , virt ) = try let ( id , mut ' , virt ' , ty ' ) = Vars . find lab ! vars in if mut ' <> mut then raise ( Error ( loc , val_env , Mutability_mismatch ( lab , mut ) ) ) ; Ctype . uni... |
let concr_vals vars = Vars . fold ( fun id ( _ , vf , _ ) s -> if vf = Virtual then s else Concr . add id s ) vars Concr . empty |
let inheritance self_type env ovf concr_meths warn_vals loc parent = match scrape_class_type parent with Cty_signature cl_sig -> begin try Ctype . unify env self_type cl_sig . csig_self with Ctype . Unify trace -> let open Ctype . Unification_trace in match trace with | Diff _ :: Incompatible_fields { n... |
let virtual_method val_env meths self_type lab priv sty loc = let ( _ , ty ' ) = Ctype . filter_self_method val_env lab priv meths self_type in let sty = Ast_helper . Typ . force_poly sty in let cty = transl_simple_type val_env false sty in let ty = cty . ctyp_type in begin try Ctype . unify val... |
let delayed_meth_specs = ref [ ] |
let declare_method val_env meths self_type lab priv sty loc = let ( _ , ty ' ) = Ctype . filter_self_method val_env lab priv meths self_type in let unif ty = try Ctype . unify val_env ty ty ' with Ctype . Unify trace -> raise ( Error ( loc , val_env , Field_type_mismatch ( " method " ... |
let type_constraint val_env sty sty ' loc = let cty = transl_simple_type val_env false sty in let ty = cty . ctyp_type in let cty ' = transl_simple_type val_env false sty ' in let ty ' = cty ' . ctyp_type in begin try Ctype . unify val_env ty ty ' with Ctype . Unify trace -> raise ( Error ( ... |
let make_method loc cl_num expr = let open Ast_helper in let mkid s = mkloc s loc in Exp . fun_ ~ loc : expr . pexp_loc Nolabel None ( Pat . alias ~ loc ( Pat . var ~ loc ( mkid " self " ) ) -* ( mkid ( " self " - ^ cl_num ) ) ) expr |
let add_val lab ( mut , virt , ty ) val_sig = let virt = try let ( _mut ' , virt ' , _ty ' ) = Vars . find lab val_sig in if virt ' = Concrete then virt ' else virt with Not_found -> virt in Vars . add lab ( mut , virt , ty ) val_sig |
let rec class_type_field env self_type meths arg ctf = Builtin_attributes . warning_scope ctf . pctf_attributes ( fun ( ) -> class_type_field_aux env self_type meths arg ctf ) ( fields , val_sig , concr_meths , inher ) ctf = let loc = ctf . pctf_loc in let mkctf desc = { ctf_desc = desc ... |
let class_type env scty = delayed_meth_specs := [ ] ; let cty = class_type env scty in List . iter Lazy . force ( List . rev ! delayed_meth_specs ) ; delayed_meth_specs := [ ] ; cty |
let rec class_field self_loc cl_num self_type meths vars arg cf = Builtin_attributes . warning_scope cf . pcf_attributes ( fun ( ) -> class_field_aux self_loc cl_num self_type meths vars arg cf ) ( val_env , met_env , par_env , fields , concr_meths , warn_vals , inher , local_meths , loc... |
let var_option = Predef . type_option ( Btype . newgenvar ( ) ) |
let rec approx_declaration cl = match cl . pcl_desc with Pcl_fun ( l , _ , _ , cl ) -> let arg = if Btype . is_optional l then Ctype . instance var_option else Ctype . newvar ( ) in Ctype . newty ( Tarrow ( l , arg , approx_declaration cl , Cok ) ) | Pcl_let ( _ , _ , ... |
let rec approx_description ct = match ct . pcty_desc with Pcty_arrow ( l , _ , ct ) -> let arg = if Btype . is_optional l then Ctype . instance var_option else Ctype . newvar ( ) in Ctype . newty ( Tarrow ( l , arg , approx_description ct , Cok ) ) | _ -> Ctype . newvar ( ... |
let temp_abbrev loc env id arity = let params = ref [ ] in for _i = 1 to arity do params := Ctype . newvar ( ) :: ! params done ; let ty = Ctype . newobj ( Ctype . newvar ( ) ) in let env = Env . add_type ~ check : true id { type_params = ! params ; type_arity = arity ; ty... |
let initial_env define_class approx ( res , env ) ( cl , id , ty_id , obj_id , cl_id ) = let arity = List . length cl . pci_params in let ( obj_params , obj_ty , env ) = temp_abbrev cl . pci_loc env obj_id arity in let ( cl_params , cl_ty , env ) = temp_abbrev cl . pci_loc ... |
let class_infos define_class kind ( cl , id , ty_id , obj_id , obj_params , obj_ty , cl_id , cl_params , cl_ty , constr_type , dummy_class ) ( res , env ) = reset_type_variables ( ) ; Ctype . begin_class_def ( ) ; let ci_params = let make_param ( sty , v ) = try ( ... |
let final_decl env define_class ( cl , id , clty , ty_id , cltydef , obj_id , obj_abbr , cl_id , cl_abbr , ci_params , arity , pub_meths , coe , expr ) = begin try Ctype . collapse_conj_params env clty . cty_params with Ctype . Unify trace -> raise ( Error ( cl . pci_loc , ... |
let class_infos define_class kind ( cl , id , ty_id , obj_id , obj_params , obj_ty , cl_id , cl_params , cl_ty , constr_type , dummy_class ) ( res , env ) = Builtin_attributes . warning_scope cl . pci_attributes ( fun ( ) -> class_infos define_class kind ( cl , id , ty_id... |
let extract_type_decls { clty ; cltydef ; obj_id ; obj_abbr ; cl_abbr ; req } decls = ( obj_id , obj_abbr , cl_abbr , clty , cltydef , req ) :: decls |
let merge_type_decls decl ( obj_abbr , cl_abbr , clty , cltydef ) = { decl with obj_abbr ; cl_abbr ; clty ; cltydef } |
let final_env define_class env { id ; clty ; ty_id ; cltydef ; obj_id ; obj_abbr ; cl_id ; cl_abbr } = Env . add_type ~ check : true obj_id ( Subst . type_declaration Subst . identity obj_abbr ) ( Env . add_type ~ check : true cl_id ( Subst . type_declaration Subst . identity ... |
let check_coercions env { id ; id_loc ; clty ; ty_id ; cltydef ; obj_id ; obj_abbr ; cl_id ; cl_abbr ; arity ; pub_meths ; coe ; req } = begin match coe with [ ] -> ( ) | loc :: _ -> let cl_ty , obj_ty = match cl_abbr . type_manifest , obj_abbr . type_manifest with Som... |
let type_classes define_class approx kind env cls = let scope = Ctype . create_scope ( ) in let cls = List . map ( function cl -> ( cl , Ident . create_scoped ~ scope cl . pci_name . txt , Ident . create_scoped ~ scope cl . pci_name . txt , Ident . create_scoped ~ scope cl . pci... |
let class_num = ref 0 |
let class_declaration env sexpr = incr class_num ; let expr = class_expr ( Int . to_string ! class_num ) env env sexpr in ( expr , expr . cl_type ) |
let class_description env sexpr = let expr = class_type env sexpr in ( expr , expr . cltyp_type ) |
let class_declarations env cls = let info , env = type_classes true approx_declaration class_declaration env cls in let ids , exprs = List . split ( List . map ( fun ci -> ci . cls_id , ci . cls_info . ci_expr ) info ) in check_recursive_class_bindings env ids exprs ; info , env |
let class_descriptions env cls = type_classes true approx_description class_description env cls |
let class_type_declarations env cls = let ( decls , env ) = type_classes false approx_description class_description env cls in ( List . map ( fun decl -> { clsty_ty_id = decl . cls_ty_id ; clsty_id_loc = decl . cls_id_loc ; clsty_ty_decl = decl . cls_ty_decl ; clsty_obj_id = decl . cl... |
let rec unify_parents env ty cl = match cl . cl_desc with Tcl_ident ( p , _ , _ ) -> begin try let decl = Env . find_class p env in let _ , body = Ctype . find_cltype_for_path env decl . cty_path in Ctype . unify env ty ( Ctype . instance body ) with Not_found -> ( ) | _exn -> a... |
let type_object env loc s = incr class_num ; let ( desc , sign ) = class_structure ( Int . to_string ! class_num ) true env env loc s in let sty = Ctype . expand_head env sign . csig_self in Ctype . hide_private_methods sty ; let ( fields , _ ) = Ctype . flatten_fields ( Ctype . ... |
let ( ) = Typecore . type_object := type_object |
let approx_class sdecl = let open Ast_helper in let self ' = Typ . any ( ) in let clty ' = Cty . signature ~ loc : sdecl . pci_expr . pcty_loc ( Csig . mk self ' [ ] ) in { sdecl with pci_expr = clty ' } |
let approx_class_declarations env sdecls = fst ( class_type_declarations env ( List . map approx_class sdecls ) ) |
let report_error env ppf = function | Repeated_parameter -> fprintf ppf " A type parameter occurs several times " | Unconsistent_constraint trace -> fprintf ppf " The class constraints are not consistent . . " ; @ Printtyp . report_unification_error ppf env trace ( fun ppf -> fprintf ppf " Ty... |
let report_error env ppf err = Printtyp . wrap_printing_env ~ error : true env ( fun ( ) -> report_error env 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 ) |
type unary_interval = { upper_bound : Type . t ; lower_bound : Type . t ; } |
type callable_parameter_interval = | Top | Singleton of Type . Callable . parameters | Bottom |
type tuple_interval = | TopTuple | BottomTuple | SingletonTuple of Type . t Type . OrderedTypes . record |
type t = { unaries : unary_interval UnaryVariable . Map . t ; callable_parameters : callable_parameter_interval ParameterVariable . Map . t ; tuple_variadics : tuple_interval TupleVariable . Map . t ; have_fallbacks : Type . Variable . Set . t ; } |
let show_map map ~ show_key ~ show_data ~ short_name = if Map . is_empty map then " " else let show ~ key ~ data sofar = Printf . sprintf " % s => % s " ( show_key key ) ( show_data data ) :: sofar in Map . fold map ~ init [ ] : ~ f : show |> String . concat ~ sep " :\ n ... |
let pp format { unaries ; callable_parameters ; tuple_variadics ; have_fallbacks } = let unaries = show_map unaries ~ show_key : UnaryVariable . show ~ show_data : show_unary_interval ~ short_name " : un " in let callable_parameters = show_map callable_parameters ~ show_key : ParameterVariabl... |
let show annotation = Format . asprintf " % a " pp annotation |
let empty = { unaries = UnaryVariable . Map . empty ; callable_parameters = ParameterVariable . Map . empty ; tuple_variadics = TupleVariable . Map . empty ; have_fallbacks = Type . Variable . Set . empty ; } |
let exists_in_bounds { unaries ; callable_parameters ; tuple_variadics ; _ } ~ variables = let contains_variable annotation = let contains_unary = Type . Variable . GlobalTransforms . Unary . collect_all annotation |> List . exists ~ f ( : fun variable -> List . mem variables ( Type .... |
module Solution = struct type t = { unaries : Type . t UnaryVariable . Map . t ; callable_parameters : Type . Callable . parameters ParameterVariable . Map . t ; tuple_variadics : Type . t Type . OrderedTypes . record TupleVariable . Map . t ; } let equal left right = UnaryVariab... |
module type OrderedConstraintsType = sig type order val add_lower_bound : t -> order : order -> pair : Type . Variable . pair -> t option val add_upper_bound : t -> order : order -> pair : Type . Variable . pair -> t option val add_fallback_to_any : t -> Type . Variable . t -> t val solve :... |
module type OrderType = sig type t val always_less_or_equal : t -> left : Type . t -> right : Type . t -> bool val meet : t -> Type . t -> Type . t -> Type . t val join : t -> Type . t -> Type . t -> Type . t end |
module OrderedConstraints ( Order : OrderType ) = struct module IntervalContainer = struct module type Interval = sig module Variable : Type . Variable . VariableKind type t val create : ? upper_bound : Variable . domain -> ? lower_bound : Variable . domain -> unit -> t val intersection : t -... |
let empty_head variable = { Type . Callable . head = [ ] ; variable } |
let child = Type . Primitive " Child " |
let left_parent = Type . Primitive " left_parent " |
let right_parent = Type . Primitive " right_parent " |
let grandparent = Type . Primitive " Grandparent " |
module DiamondOrder = struct type t = unit let rec always_less_or_equal _ ~ left ~ right = match left , right with | _ , _ when Type . equal left right -> true | _ , Type . Top -> true | Type . Bottom , _ -> true | Type . Primitive " Child " , Type . Primitive " left_parent " ... |
module DiamondOrderedConstraints = OrderedConstraints ( DiamondOrder ) |
let variable ( ? name = " _V " ) constraints = Type . Variable . Unary . create name ~ constraints |
let add_bound constraints bound = let order = ( ) in constraints >>= fun constraints -> match bound with | ` Lower pair -> DiamondOrderedConstraints . add_lower_bound constraints ~ order ~ pair | ` Upper pair -> DiamondOrderedConstraints . add_upper_bound constraints ~ order ~ pair | ` Fallba... |
let test_add_bound _ = let assert_add_bound_has_result ( ? preconstraints = Some empty ) bound ~ expected_is_some = let result = add_bound preconstraints bound |> Option . is_some in assert_equal ~ printer ( : Printf . sprintf " % B " ) expected_is_some result in let assert_add_bound_succeeds... |
let optional_map_compare left right = match left , right with | Some left , Some right -> TypeConstraints . Solution . equal left right | None , None -> true | _ , _ -> false |
let optional_map_print map = map >>| TypeConstraints . Solution . show |> Option . value ~ default " : None " |
let assert_solution ~ sequentially_applied_bounds expected = let result = List . fold sequentially_applied_bounds ~ init ( : Some empty ) ~ f : add_bound >>= DiamondOrderedConstraints . solve ~ order ( ) : in let expected = expected >>| TypeConstraints . Solution . create in assert_equal ~ ... |
let test_single_variable_solution _ = assert_solution ~ sequentially_applied_bounds [ ] : ( Some [ ] ) ; let unconstrained = variable Type . Variable . Unconstrained in assert_solution ~ sequentially_applied_bounds [ ` : Lower ( UnaryPair ( unconstrained , child ) ) ] ( Some [... |
let test_multiple_variable_solution _ = let unconstrained_a = variable ~ name " : A " Type . Variable . Unconstrained in let unconstrained_b = variable ~ name " : B " Type . Variable . Unconstrained in assert_solution ~ sequentially_applied_bounds : [ ` Lower ( UnaryPair ( unconstraine... |
let test_partial_solution _ = let expect_split_solution ~ bounds ~ variables expected_partial_solution expected_remainder_solution = let partial_result , remainder_solution = List . fold bounds ~ init ( : Some empty ) ~ f : add_bound >>= DiamondOrderedConstraints . extract_partial_solution ~ order... |
let test_exists _ = let order = ( ) in let unconstrained_a = variable ~ name " : A " Type . Variable . Unconstrained in let unconstrained_b = variable ~ name " : B " Type . Variable . Unconstrained in let constraints_with_unconstrained_b = let pair = Type . Variable . UnaryPair ( un... |
let ( ) = " constraints " >::: [ " add_bound " >:: test_add_bound ; " single_variable " >:: test_single_variable_solution ; " multiple_variables " >:: test_multiple_variable_solution ; " partial_solution " >:: test_partial_solution ; " exists " >:: test_exists ; ] |> Te... |
type type_forcing_context = | If_conditional | If_no_else_branch | While_loop_conditional | While_loop_body | For_loop_start_index | For_loop_stop_index | For_loop_body | Assert_condition | Sequence_left_hand_side | When_guard |
type type_expected = { ty : type_expr ; explanation : type_forcing_context option ; } |
type existential_restriction = | At_toplevel | In_group | In_rec | With_attributes | In_class_args | In_class_def | In_self_pattern |
type error = | Constructor_arity_mismatch of Longident . t * int * int | Label_mismatch of Longident . t * Ctype . Unification_trace . t | Pattern_type_clash of Ctype . Unification_trace . t * pattern_desc option | Or_pattern_type_clash of Ident . t * Ctype . Unification_trace . t | Multipl... |
let type_module = ref ( ( fun _env _md -> assert false ) : Env . t -> Parsetree . module_expr -> Typedtree . module_expr ) |
let type_open : ( ? used_slot : bool ref -> override_flag -> Env . t -> Location . t -> Longident . t loc -> Path . t * Env . t ) ref = ref ( fun ? used_slot : _ _ -> assert false ) |
let type_open_decl : ( ? used_slot : bool ref -> Env . t -> Parsetree . open_declaration -> open_declaration * Types . signature * Env . t ) ref = ref ( fun ? used_slot : _ _ -> assert false ) |
let type_package = ref ( fun _ -> assert false ) |
let type_object = ref ( fun _env _s -> assert false : Env . t -> Location . t -> Parsetree . class_structure -> Typedtree . class_structure * Types . class_signature * string list ) |
let re node = Cmt_format . add_saved_type ( Cmt_format . Partial_expression node ) ; Stypes . record ( Stypes . Ti_expr node ) ; node ; ; |
let rp node = Cmt_format . add_saved_type ( Cmt_format . Partial_pattern node ) ; Stypes . record ( Stypes . Ti_pat node ) ; node ; ; |
type recarg = | Allowed | Required | Rejected |
let mk_expected ? explanation ty = { ty ; explanation ; } |
let case lhs rhs = { c_lhs = lhs ; c_guard = None ; c_rhs = rhs } |
let type_constant = function Const_int _ -> instance Predef . type_int | Const_char _ -> instance Predef . type_char | Const_string _ -> instance Predef . type_string | Const_float _ -> instance Predef . type_float | Const_int32 _ -> instance Predef . type_int32 | Const_int64 _ -> instance P... |
let constant : Parsetree . constant -> ( Asttypes . constant , error ) result = function | Pconst_integer ( i , None ) -> begin try Ok ( Const_int ( Misc . Int_literal_converter . int i ) ) with Failure _ -> Error ( Literal_overflow " int " ) end | Pconst_integer ( i , So... |
let constant_or_raise env loc cst = match constant cst with | Ok c -> c | Error err -> raise ( Error ( loc , env , err ) ) |
let type_option ty = newty ( Tconstr ( Predef . path_option , [ ty ] , ref Mnil ) ) |
let mkexp exp_desc exp_type exp_loc exp_env = { exp_desc ; exp_type ; exp_loc ; exp_env ; exp_extra = [ ] ; exp_attributes = [ ] } |
let option_none env ty loc = let lid = Longident . Lident " None " in let cnone = Env . find_ident_constructor Predef . ident_none env in mkexp ( Texp_construct ( mknoloc lid , cnone , [ ] ) ) ty loc env |
let option_some env texp = let lid = Longident . Lident " Some " in let csome = Env . find_ident_constructor Predef . ident_some env in mkexp ( Texp_construct ( mknoloc lid , csome , [ texp ] ) ) ( type_option texp . exp_type ) texp . exp_loc texp . exp_env |
let extract_option_type env ty = match expand_head env ty with { desc = Tconstr ( path , [ ty ] , _ ) } when Path . same path Predef . path_option -> ty | _ -> assert false |
let extract_concrete_record env ty = match extract_concrete_typedecl env ty with ( p0 , p , { type_kind = Type_record ( fields , _ ) } ) -> ( p0 , p , fields ) | _ -> raise Not_found |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.