text stringlengths 0 601k |
|---|
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 " -> true | Type . Primitive " Child " , Type... |
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 | ` Fallback variable -> DiamondOrder... |
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 = assert_add_bound_has_res... |
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 ~ cmp : optional_map_compare ~ ... |
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 [ UnaryPair ( unconstrained , child ) ] ) ; ... |
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 ( unconstrained_a , Type . Variable 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 ( ) : ~ variables >>|... |
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 ( unconstrained_a , Type . Variable uncon... |
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 ; ] |> Test . run |
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 | Multiply_bound_variable of string | ... |
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 Predef . type_int64 | Const_n... |
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 , Some ' l ' ) -> begin try Ok ( Const_int32 ( Misc ... |
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 |
let extract_concrete_variant env ty = match extract_concrete_typedecl env ty with ( p0 , p , { type_kind = Type_variant cstrs } ) -> ( p0 , p , cstrs ) | ( p0 , p , { type_kind = Type_open } ) -> ( p0 , p , [ ] ) | _ -> raise Not_found |
let extract_label_names env ty = try let ( _ , _ , fields ) = extract_concrete_record env ty in List . map ( fun l -> l . Types . ld_id ) fields with Not_found -> assert false |
let unify_exp_types loc env ty expected_ty = try unify env ty expected_ty with Unify trace -> raise ( Error ( loc , env , Expr_type_clash ( trace , None , None ) ) ) | Tags ( l1 , l2 ) -> raise ( Typetexp . Error ( loc , env , Typetexp . Variant_tags ( l1 , l2 ) ) ) |
let gadt_equations_level = ref None |
let get_gadt_equations_level ( ) = match ! gadt_equations_level with Some y -> y | None -> assert false |
let unify_pat_types ( ? refine = false ) loc env ty ty ' = try if refine then unify_gadt ~ equations_level ( : get_gadt_equations_level ( ) ) env ty ty ' else unify ! env ty ty ' with | Unify trace -> raise ( Error ( loc , ! env , Pattern_type_clash ( trace , None ) ) ) | Tags ( l1 , l2 ) -> raise ( Typetexp . Error ( ... |
let unify_pat ? refine env pat expected_ty = try unify_pat_types ? refine pat . pat_loc env pat . pat_type expected_ty with Error ( loc , env , Pattern_type_clash ( trace , None ) ) -> raise ( Error ( loc , env , Pattern_type_clash ( trace , Some pat . pat_desc ) ) ) |
let finalize_variant pat = match pat . pat_desc with Tpat_variant ( tag , opat , r ) -> let row = match expand_head pat . pat_env pat . pat_type with { desc = Tvariant row } -> r := row ; row_repr row | _ -> assert false in begin match row_field tag row with | Rabsent -> ( ) | Reither ( true , [ ] , _ , e ) when not ro... |
let has_variants p = exists_pattern ( function { pat_desc = Tpat_variant _ } -> true | _ -> false ) p |
type pattern_variable = { pv_id : Ident . t ; pv_type : type_expr ; pv_loc : Location . t ; pv_as_var : bool ; pv_attributes : attributes ; } |
type module_variable = string loc * Location . t |
let pattern_variables = ref ( [ ] : pattern_variable list ) |
let pattern_force = ref ( [ ] : ( unit -> unit ) list ) |
let pattern_scope = ref ( None : Annot . ident option ) ; ; |
let allow_modules = ref false |
let module_variables = ref ( [ ] : module_variable list ) |
let reset_pattern scope allow = pattern_variables := [ ] ; pattern_force := [ ] ; pattern_scope := scope ; allow_modules := allow ; module_variables := [ ] ; ; ; |
let maybe_add_pattern_variables_ghost loc_let env pv = List . fold_right ( fun { pv_id ; _ } env -> let name = Ident . name pv_id in if Env . bound_value name env then env else begin Env . enter_unbound_value name ( Val_unbound_ghost_recursive loc_let ) env end ) pv env |
let enter_variable ( ? is_module = false ) ( ? is_as_variable = false ) loc name ty attrs = if List . exists ( fun { pv_id ; _ } -> Ident . name pv_id = name . txt ) ! pattern_variables then raise ( Error ( loc , Env . empty , Multiply_bound_variable name . txt ) ) ; let id = Ident . create_local name . txt in pattern_... |
let sort_pattern_variables vs = List . sort ( fun { pv_id = x ; _ } { pv_id = y ; _ } -> Stdlib . compare ( Ident . name x ) ( Ident . name y ) ) vs |
let enter_orpat_variables loc env p1_vs p2_vs = let p1_vs = sort_pattern_variables p1_vs and p2_vs = sort_pattern_variables p2_vs in let rec unify_vars p1_vs p2_vs = let vars vs = List . map ( fun { pv_id ; _ } -> pv_id ) vs in match p1_vs , p2_vs with | { pv_id = x1 ; pv_type = t1 ; _ } :: rem1 , { pv_id = x2 ; pv_typ... |
let rec build_as_type env p = match p . pat_desc with Tpat_alias ( p1 , _ , _ ) -> build_as_type env p1 | Tpat_tuple pl -> let tyl = List . map ( build_as_type env ) pl in newty ( Ttuple tyl ) | Tpat_construct ( _ , cstr , pl ) -> let keep = cstr . cstr_private = Private || cstr . cstr_existentials <> [ ] in if keep th... |
let build_or_pat env loc lid = let path , decl = Env . lookup_type ~ loc : lid . loc lid . txt env in let tyl = List . map ( fun _ -> newvar ( ) ) decl . type_params in let row0 = let ty = expand_head env ( newty ( Tconstr ( path , tyl , ref Mnil ) ) ) in match ty . desc with Tvariant row when static_row row -> row | _... |
let split_cases env cases = let add_case lst case = function | None -> lst | Some c_lhs -> { case with c_lhs } :: lst in List . fold_right ( fun ( { c_lhs ; c_guard } as case ) ( vals , exns ) -> match split_pattern c_lhs with | Some _ , Some _ when c_guard <> None -> raise ( Error ( c_lhs . pat_loc , env , Mixed_value... |
let rec expand_path env p = let decl = try Some ( Env . find_type p env ) with Not_found -> None in match decl with Some { type_manifest = Some ty } -> begin match repr ty with { desc = Tconstr ( p , _ , _ ) } -> expand_path env p | _ -> assert false end | _ -> let p ' = Env . normalize_type_path None env p in if Path ... |
let compare_type_path env tpath1 tpath2 = Path . same ( expand_path env tpath1 ) ( expand_path env tpath2 ) |
let label_of_kind kind = if kind = " record " then " field " else " constructor " |
module NameChoice ( Name : sig type t type usage val type_kind : string val get_name : t -> string val get_type : t -> type_expr val lookup_all_from_type : Location . t -> usage -> Path . t -> Env . t -> ( t * ( unit -> unit ) ) list val in_env : t -> bool open Name let get_type_path d = match ( repr ( get_type d ) ) .... |
let wrap_disambiguate kind ty f x = try f x with Error ( loc , env , Wrong_name ( " " , _ , tk , tp , name , valid_names ) ) -> raise ( Error ( loc , env , Wrong_name ( kind , ty , tk , tp , name , valid_names ) ) ) |
module Label = NameChoice ( struct type t = label_description type usage = unit let type_kind = " record " let get_name lbl = lbl . lbl_name let get_type lbl = lbl . lbl_res let lookup_all_from_type loc ( ) path env = Env . lookup_all_labels_from_type ~ loc path env let in_env lbl = match lbl . lbl_repres with | Record... |
let disambiguate_label_by_ids keep closed ids labels = let check_ids ( lbl , _ ) = let lbls = Hashtbl . create 8 in Array . iter ( fun lbl -> Hashtbl . add lbls lbl . lbl_name ( ) ) lbl . lbl_all ; List . for_all ( Hashtbl . mem lbls ) ids and check_closed ( lbl , _ ) = ( not closed || List . length ids = Array . lengt... |
let disambiguate_lid_a_list loc closed env opath lid_a_list = let ids = List . map ( fun ( lid , _ ) -> Longident . last lid . txt ) lid_a_list in let w_pr = ref false and w_amb = ref [ ] and w_scope = ref [ ] and w_scope_ty = ref " " in let warn loc msg = let open Warnings in match msg with | Not_principal _ -> w_pr :... |
let rec find_record_qual = function | [ ] -> None | ( { txt = Longident . Ldot ( modname , _ ) } , _ ) :: _ -> Some modname | _ :: rest -> find_record_qual rest |
let map_fold_cont f xs k = List . fold_right ( fun x k ys -> f x ( fun y -> k ( y :: ys ) ) ) xs ( fun ys -> k ( List . rev ys ) ) [ ] |
let type_label_a_list ? labels loc closed env type_lbl_a opath lid_a_list k = let lbl_a_list = match lid_a_list , labels with ( { txt = Longident . Lident s } , _ ) :: _ , Some labels when Hashtbl . mem labels s -> List . map ( function lid , a -> match lid . txt with Longident . Lident s -> lid , Hashtbl . find labels... |
let check_recordpat_labels loc lbl_pat_list closed = match lbl_pat_list with | [ ] -> ( ) | ( _ , label1 , _ ) :: _ -> let all = label1 . lbl_all in let defined = Array . make ( Array . length all ) false in let check_defined ( _ , label , _ ) = if defined . ( label . lbl_pos ) then raise ( Error ( loc , Env . empty , ... |
module Constructor = NameChoice ( struct type t = constructor_description type usage = Env . constructor_usage let type_kind = " variant " let get_name cstr = cstr . cstr_name let get_type cstr = cstr . cstr_res let lookup_all_from_type loc usage path env = Env . lookup_all_constructors_from_type ~ loc usage path env l... |
let unify_head_only ~ refine loc env ty constr = let ( _ , ty_res ) = instance_constructor constr in let ty_res = repr ty_res in match ty_res . desc with | Tconstr ( p , args , m ) -> ty_res . desc <- Tconstr ( p , List . map ( fun _ -> newvar ( ) ) args , m ) ; enforce_constraints ! env ty_res ; unify_pat_types ~ refi... |
type half_typed_case = { typed_pat : pattern ; pat_type_for_unif : type_expr ; untyped_case : Parsetree . case ; branch_env : Env . t ; pat_vars : pattern_variable list ; unpacks : module_variable list ; contains_gadt : bool ; } |
let rec has_literal_pattern p = match p . ppat_desc with | Ppat_constant _ | Ppat_interval _ -> true | Ppat_any | Ppat_variant ( _ , None ) | Ppat_construct ( _ , None ) | Ppat_type _ | Ppat_var _ | Ppat_unpack _ | Ppat_extension _ -> false | Ppat_exception p | Ppat_variant ( _ , Some p ) | Ppat_construct ( _ , Some p ... |
let check_scope_escape loc env level ty = try Ctype . check_scope_escape env level ty with Unify trace -> raise ( Error ( loc , env , Pattern_type_clash ( trace , None ) ) ) |
type pattern_checking_mode = | Normal | Counter_example of counter_example_checking_info explosion_fuel : int ; splitting_mode : splitting_mode ; constrs : ( string , Types . constructor_description ) Hashtbl . t ; labels : ( string , Types . label_description ) Hashtbl . t ; } | Backtrack_or | Refine_or of { inside_no... |
type state = { snapshot : Btype . snapshot ; levels : Ctype . levels ; env : Env . t ; } |
let save_state env = { snapshot = Btype . snapshot ( ) ; levels = Ctype . save_levels ( ) ; env = ! env ; } |
let set_state s env = Btype . backtrack s . snapshot ; Ctype . set_levels s . levels ; env := s . env |
let rec find_valid_alternative f pat = match pat . ppat_desc with | Ppat_or ( p1 , p2 ) -> ( try find_valid_alternative f p1 with Error _ -> find_valid_alternative f p2 ) | _ -> f pat |
let no_explosion = function | Normal -> Normal | Counter_example info -> Counter_example { info with explosion_fuel = 0 } |
let get_splitting_mode = function | Normal -> None | Counter_example { splitting_mode } -> Some splitting_mode |
let enter_nonsplit_or mode = match mode with | Normal -> Normal | Counter_example info -> let splitting_mode = match info . splitting_mode with | Backtrack_or -> assert false | Refine_or _ -> Refine_or { inside_nonsplit_or = true } in Counter_example { info with splitting_mode } |
let rec type_pat ( ? exception_allowed = false ) ~ no_existentials ~ mode ~ env sp expected_ty k = Builtin_attributes . warning_scope sp . ppat_attributes ( fun ( ) -> type_pat_aux ~ exception_allowed ~ no_existentials ~ mode ~ env sp expected_ty k ) ~ env sp expected_ty k = let type_pat ( ? exception_allowed = false )... |
let type_pat ? exception_allowed ? no_existentials ( ? mode = Normal ) ( ? lev = get_current_level ( ) ) env sp expected_ty = Misc . protect_refs [ Misc . R ( gadt_equations_level , Some lev ) ] ( fun ( ) -> let r = type_pat ? exception_allowed ~ no_existentials ~ mode ~ env sp expected_ty ( fun x -> x ) in iter_patter... |
let partial_pred ~ lev ~ splitting_mode ( ? explode = 0 ) env expected_ty constrs labels p = let env = ref env in let state = save_state env in let mode = Counter_example { splitting_mode ; explosion_fuel = explode ; constrs ; labels ; } in try reset_pattern None true ; let typed_p = Ctype . with_passive_variants ( typ... |
let check_partial ( ? lev = get_current_level ( ) ) env expected_ty loc cases = let explode = match cases with [ _ ] -> 5 | _ -> 0 in let splitting_mode = Refine_or { inside_nonsplit_or = false } in Parmatch . check_partial ( partial_pred ~ lev ~ splitting_mode ~ explode env expected_ty ) loc cases |
let check_unused ( ? lev = get_current_level ( ) ) env expected_ty cases = Parmatch . check_unused ( fun refute constrs labels spat -> match partial_pred ~ lev ~ splitting_mode : Backtrack_or ~ explode : 5 env expected_ty constrs labels spat with Some pat when refute -> raise ( Error ( spat . ppat_loc , env , Unrefuted... |
let iter_pattern_variables_type f : pattern_variable list -> unit = List . iter ( fun { pv_type ; _ } -> f pv_type ) |
let add_pattern_variables ? check ? check_as env pv = List . fold_right ( fun { pv_id ; pv_type ; pv_loc ; pv_as_var ; pv_attributes } env -> let check = if pv_as_var then check_as else check in Env . add_value ? check pv_id { val_type = pv_type ; val_kind = Val_reg ; Types . val_loc = pv_loc ; val_attributes = pv_attr... |
let type_pattern ? exception_allowed ~ lev env spat scope expected_ty = reset_pattern scope true ; let new_env = ref env in let pat = type_pat ? exception_allowed ~ lev new_env spat expected_ty in let pvs = get_ref pattern_variables in let unpacks = get_ref module_variables in ( pat , ! new_env , get_ref pattern_force ... |
let type_pattern_list no_existentials env spatl scope expected_tys allow = reset_pattern scope allow ; let new_env = ref env in let type_pat ( attrs , pat ) ty = Builtin_attributes . warning_scope ~ ppwarning : false attrs ( fun ( ) -> type_pat ~ no_existentials new_env pat ty ) in let patl = List . map2 type_pat spatl... |
let type_class_arg_pattern cl_num val_env met_env l spat = reset_pattern None false ; let nv = newvar ( ) in let pat = type_pat ~ no_existentials : In_class_args ( ref val_env ) spat nv in if has_variants pat then begin Parmatch . pressure_variants val_env [ pat ] ; iter_pattern finalize_variant pat end ; List . iter (... |
let type_self_pattern cl_num privty val_env met_env par_env spat = let open Ast_helper in let spat = Pat . mk ( Ppat_alias ( Pat . mk ( Ppat_alias ( spat , mknoloc " selfpat " ) ) , -* mknoloc ( " selfpat " - ^ cl_num ) ) ) in reset_pattern None false ; let nv = newvar ( ) in let pat = type_pat ~ no_existentials : In_s... |
let delayed_checks = ref [ ] |
let reset_delayed_checks ( ) = delayed_checks := [ ] |
let add_delayed_check f = delayed_checks := ( f , Warnings . backup ( ) ) :: ! delayed_checks |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.