text stringlengths 0 601k |
|---|
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 = TypeMap . empty ; poison ... |
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 | ( Tlink _ , _ ) -> assert fa... |
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 . find var context with Not_fou... |
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 . type_loc ~ parameters :... |
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 ( ) = compute_decl env dec... |
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_immediate = Always ; _ } -> This Predef ... |
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 compute_same = compute_variance... |
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 . empty in let open Variance in List . iter ( fun ( cn... |
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 = Tconstr ( _ , tyl , _ ) } -> let ty... |
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_abstract || i ) ) required else let mn = match decl . ty... |
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 _ -> Variance . null ) decl . type_... |
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 ( [ ] , [ ] ) in let decls = Typedecl_properties . compute_prope... |
type type_decl = { td_name : string ; td_mod : string ; td_type : idltype ; td_abstract : bool ; td_c2ml : string option ; td_ml2c : string option ; td_finalize : string option ; td_compare : string option ; td_hash : string option ; td_errorcode : bool ; td_errorcheck : string option ; td_mltype : string option } |
let find = ref ( ( fun _ -> invalid_arg " Typedef . find " ) : string -> type_decl ) |
let ml_declaration oc td = match td with { td_mltype = Some s } -> fprintf oc " % s = % s \ n " ( String . uncapitalize_ascii td . td_name ) s | { td_abstract = true } -> fprintf oc " % s \ n " ( String . uncapitalize_ascii td . td_name ) | _ -> fprintf oc " % s = % a \ n " ( String . uncapitalize_ascii td . td_name ) ... |
let c_declaration oc td = fprintf oc " typedef % a ; \ n " out_c_decl ( td . td_name , td . td_type ) ; begin match td . td_ml2c with None -> ( ) | Some s -> fprintf oc " extern void % s ( value , % s ) ; *\ n " s td . td_name end ; begin match td . td_c2ml with None -> ( ) | Some s -> fprintf oc " extern value % s ( %... |
let declare_transl oc td = begin match td . td_ml2c with Some s -> fprintf oc " extern void % s ( value , % s ) ; *\ n " s td . td_name ; fprintf oc " # define camlidl_ml2c_ % s_ % s ( v , c , ctx ) % s ( v , c ) \ n \ n " td . td_mod td . td_name s | None -> fprintf oc " extern void camlidl_ml2c_ % s_ % s ( value , % ... |
let is_custom_block td = td . td_abstract && not ( td . td_finalize = None && td . td_compare = None && td . td_hash = None ) |
let transl_ml_to_c oc td = current_function := sprintf " typedef % s " td . td_name ; let v = new_var " _v " in let c = new_var " _c " in fprintf oc " void camlidl_ml2c_ % s_ % s ( value % s , % s * % s , camlidl_ctx _ctx ) \ n " td . td_mod td . td_name v td . td_name c ; fprintf oc " { \ n " ; let pc = divert_output ... |
let transl_c_to_ml oc td = begin match td . td_finalize with None -> ( ) | Some f -> fprintf oc " \ { % s ( ( % s ) * Data_custom_val ( v ) ) ; } end ; begin match td . td_compare with None -> ( ) | Some f -> fprintf oc " \ { return % s ( ( % s ) * Data_custom_val ( v1 ) , ( % s ) * Data_custom_val ( v2 ) ) ; } end ; b... |
let emit_transl oc td = begin match td . td_ml2c with Some s -> fprintf oc " # define camlidl_ml2c_ % s_ % s ( v , c , ctx ) % s ( v , c ) \ n \ n " td . td_mod td . td_name s | None -> transl_ml_to_c oc td end ; begin match td . td_c2ml with Some s -> fprintf oc " # define camlidl_c2ml_ % s_ % s ( c , ctx ) % s ( c ) ... |
module Inductive = struct type notation = Name . t * VarEnv . t * Type . t type t = { constructor_records : ( Name . t * ( AdtConstructors . RecordSkeleton . t * VarEnv . t * Type . t ) t list ) list list ; notations : notation list ; records : AdtConstructors . RecordSkeleton . t list ; typs : ( Name . t * Name . t li... |
type t = | Inductive of Inductive . t | Record of Name . t * VarEnv . t * ( Name . t * Type . t ) t list * bool | Synonym of Name . t * Name . t list * Type . t | ExtensibleTyp of Name . t | Abstract of Name . t * Name . t list |
let filter_in_free_vars ( typ_args : Name . t list ) list ( free_vars : Name . Set . t ) t : Name . t list = typ_args |> List . filter_map ( function typ_arg -> if Name . Set . mem typ_arg free_vars then Some typ_arg else None ) None |
let of_ocaml ( typs : type_declaration list ) list : t Monad . t = match typs with | [ { typ_id ; typ_type = { type_manifest = Some typ ; type_params ; _ } ; _ } ] -> ( let * name = Name . of_ident false typ_id in AdtParameters . of_ocaml type_params >>= fun ind_vars -> let typ_args = AdtParameters . get_parameters ind... |
let to_coq ( fargs : FArgs . t ) t ( def : t ) t : SmartPrint . t = match def with | Inductive inductive -> Inductive . to_coq fargs inductive | Record ( name , typ_args , fields , with_with ) with_with -> AdtConstructors . RecordSkeleton . to_coq_record name name typ_args fields with_with | Synonym ( name , typ_args ,... |
type partial = Partial | Total |
type attributes = attribute list |
type pattern = { pat_desc : pattern_desc ; pat_loc : Location . t ; pat_extra : ( pat_extra * Location . t * attribute list ) list ; pat_type : type_expr ; mutable pat_env : Env . t ; pat_attributes : attribute list ; } | Tpat_constraint of core_type | Tpat_type of Path . t * Longident . t loc | Tpat_open of Path . t *... |
let shallow_iter_pattern_desc f = function | Tpat_alias ( p , _ , _ ) -> f p | Tpat_tuple patl -> List . iter f patl | Tpat_construct ( _ , _ , patl ) -> List . iter f patl | Tpat_variant ( _ , pat , _ ) -> Option . iter f pat | Tpat_record ( lbl_pat_list , _ ) -> List . iter ( fun ( _ , _ , pat ) -> f pat ) lbl_pat_li... |
let shallow_map_pattern_desc f d = match d with | Tpat_alias ( p1 , id , s ) -> Tpat_alias ( f p1 , id , s ) | Tpat_tuple pats -> Tpat_tuple ( List . map f pats ) | Tpat_record ( lpats , closed ) -> Tpat_record ( List . map ( fun ( lid , l , p ) -> lid , l , f p ) lpats , closed ) | Tpat_construct ( lid , c , pats ) ->... |
let rec iter_pattern f p = f p ; shallow_iter_pattern_desc ( iter_pattern f ) p . pat_desc |
let exists_pattern f p = let exception Found in let raiser f x = if ( f x ) then raise Found else ( ) in match iter_pattern ( raiser f ) p with | exception Found -> true | ( ) -> false |
let rec iter_bound_idents f pat = match pat . pat_desc with | Tpat_var ( id , s ) -> f ( id , s , pat . pat_type ) | Tpat_alias ( p , id , s ) -> iter_bound_idents f p ; f ( id , s , pat . pat_type ) | Tpat_or ( p1 , _ , _ ) -> iter_bound_idents f p1 | d -> shallow_iter_pattern_desc ( iter_bound_idents f ) d |
let rev_pat_bound_idents_full pat = let idents_full = ref [ ] in let add id_full = idents_full := id_full :: ! idents_full in iter_bound_idents add pat ; ! idents_full |
let rev_only_idents idents_full = List . rev_map ( fun ( id , _ , _ ) -> id ) idents_full |
let pat_bound_idents_full pat = List . rev ( rev_pat_bound_idents_full pat ) |
let pat_bound_idents pat = rev_only_idents ( rev_pat_bound_idents_full pat ) |
let rev_let_bound_idents_full bindings = let idents_full = ref [ ] in let add id_full = idents_full := id_full :: ! idents_full in List . iter ( fun vb -> iter_bound_idents add vb . vb_pat ) bindings ; ! idents_full |
let let_bound_idents_full bindings = List . rev ( rev_let_bound_idents_full bindings ) |
let let_bound_idents pat = rev_only_idents ( rev_let_bound_idents_full pat ) |
let alpha_var env id = List . assoc id env |
let rec alpha_pat env p = match p . pat_desc with { p with pat_desc = try Tpat_var ( alpha_var env id , s ) with | Not_found -> Tpat_any } let new_p = alpha_pat env p1 in begin try { p with pat_desc = Tpat_alias ( new_p , alpha_var env id , s ) } with | Not_found -> new_p end { p with pat_desc = shallow_map_pattern_des... |
let split_pattern pat = let combine_pattern_desc_opts ~ into p1 p2 = match p1 , p2 with | None , None -> None | Some p , None | None , Some p -> Some p | Some p1 , Some p2 -> Some { into with pat_desc = Tpat_or ( p1 , p2 , None ) } in let rec split_pattern pat = match pat . pat_desc with | Tpat_or ( p1 , p2 , None ) ->... |
module type IteratorArgument = sig val enter_structure : structure -> unit val enter_value_description : value_description -> unit val enter_type_extension : type_extension -> unit val enter_extension_constructor : extension_constructor -> unit val enter_pattern : pattern -> unit val enter_expression : expression -> un... |
module MakeIterator ( Iter : IteratorArgument ) : sig val iter_structure : structure -> unit val iter_signature : signature -> unit val iter_structure_item : structure_item -> unit val iter_signature_item : signature_item -> unit val iter_expression : expression -> unit val iter_module_type : module_type -> unit val it... |
module DefaultIteratorArgument = struct let enter_structure _ = ( ) let enter_value_description _ = ( ) let enter_type_extension _ = ( ) let enter_extension_constructor _ = ( ) let enter_pattern _ = ( ) let enter_expression _ = ( ) let enter_package_type _ = ( ) let enter_signature _ = ( ) let enter_signature_item _ = ... |
module type MapArgument = sig val enter_structure : structure -> structure val enter_value_description : value_description -> value_description val enter_type_declaration : type_declaration -> type_declaration val enter_type_extension : type_extension -> type_extension val enter_extension_constructor : extension_constr... |
module MakeMap ( Map : MapArgument ) = struct open Misc let rec map_structure str = let str = Map . enter_structure str in let str_items = List . map map_structure_item str . str_items in Map . leave_structure { str with str_items = str_items } and map_binding vb = { vb_pat = map_pattern vb . vb_pat ; vb_expr = map_exp... |
module DefaultMapArgument = struct let enter_structure t = t let enter_value_description t = t let enter_type_declaration t = t let enter_type_extension t = t let enter_extension_constructor t = t let enter_pattern t = t let enter_expression t = t let enter_package_type t = t let enter_signature t = t let enter_signatu... |
let { Logger . log } = Logger . for_section " typedtrie " |
module StampMap = Map . Make ( struct type t = int let compare ( x : int ) ( y : int ) = compare x y end ) |
module Trie : sig [ @@@ ocaml . warning " - 30 " ] type t and elt = { loc : Location . t ; doc : string option ; namespace : Namespaced_path . Namespace . t ; node : node } and node = | Leaf | Internal of t Lazy . t | Included of include_ | Alias of Namespaced_path . t | Functor of functor_parameter * node | Apply of f... |
let extract_doc ( attrs : Parsetree . attributes ) = String . concat ~ sep " :\ n " ( List . filter_map attrs ~ f ( : fun attr -> Option . map ~ f : fst ( Type_utils . read_doc_attributes [ attr ] ) ) ) |
let remove_top_indir = List . concat_map ~ f ( : fun bt -> match bt . t_node with | Signature _ | Structure _ -> Lazy . force bt . t_children | _ -> [ bt ] ) |
let of_structure s = let env , node = Mbrowse . leaf_node ( Mbrowse . of_structure s ) in Browse_tree . of_node ~ env node |
let of_signature s = let env , node = Mbrowse . leaf_node ( Mbrowse . of_signature s ) in Browse_tree . of_node ~ env node |
let remove_indir_me me = match me . Typedtree . mod_desc with | Typedtree . Tmod_ident ( path , _ ) -> ` Alias path | Typedtree . Tmod_structure str -> ` Str str | Typedtree . Tmod_functor _ -> let ( fp , me ) = Typedtree . unpack_functor_me me in ` Functor ( fp , ` Mod_expr me ) | Typedtree . Tmod_apply ( me1 , me2 , ... |
let remove_indir_mty mty = match mty . Typedtree . mty_desc with | Typedtree . Tmty_alias ( path , _ ) -> ` Alias path | Typedtree . Tmty_ident ( path , _ ) -> ` Ident path | Typedtree . Tmty_signature sg -> ` Sg sg | Typedtree . Tmty_functor _ -> let ( fp , mty ) = Typedtree . unpack_functor_mty mty in ` Functor ( fp ... |
let sig_item_idns item = let open Types in let ns = match item with | Sig_value _ -> ` Vals | Sig_type _ -> ` Type | Sig_typext _ -> ` Type | Sig_module _ -> ` Mod | Sig_modtype _ -> ` Modtype | Sig_class _ -> ` Vals | Sig_class_type _ -> ` Type in signature_item_id item , ns |
let include_idents l = List . map ~ f : sig_item_idns l |
let identify_str_includes item = match item . Typedtree . str_desc with | Typedtree . Tstr_include { Typedtree . incl_type ; incl_mod ; _ } -> ` Included ( include_idents incl_type , ` Mod_expr incl_mod ) | _ -> ` Not_included |
let identify_sig_includes item = match item . Typedtree . sig_desc with | Typedtree . Tsig_include { Typedtree . incl_type ; incl_mod ; _ } -> ` Included ( include_idents incl_type , ` Mod_type incl_mod ) | _ -> ` Not_included |
let rec build ~ local_buffer ~ trie browses : t = let rec node_for_direct_mod namespace : _ -> Trie . node = function | ` Alias path -> Alias ( Namespaced_path . of_path ~ namespace path ) | ` Ident path -> Alias ( Namespaced_path . of_path ~ namespace ` : Modtype path ) | ` Str s -> Internal ( lazy ( build ~ local_buf... |
let of_browses ( ? local_buffer = false ) browses = build ~ local_buffer ~ trie : Trie . empty browses |
type scopes = ( t * Lexing . position option ) list |
type functor_argument = | Handled of Namespaced_path . t * scopes | Noop |
type substitution = { old_prefix : Namespaced_path . t ; new_prefix : Namespaced_path . t ; scopes : scopes } |
type result = | Found of Location . t * string option | Resolves_to of Namespaced_path . t * state { substs : substitution list ; functor_arguments : functor_argument list } |
let rec follow ~ remember_loc ~ state scopes ? before trie path = let trie , before , path , scopes , state = let rec try_substing_once path = function | [ ] -> None | { old_prefix ; new_prefix ; scopes } as subst :: substs -> match Namespaced_path . subst_prefix ~ old_prefix ~ new_prefix path with | Some new_path -> S... |
let initial_state = { substs = [ ] ; functor_arguments = [ ] } |
let rec find ~ remember_loc ~ before scopes trie path = match Trie . find_some ( fun _name _stmap { loc ; _ } -> Lexing . compare_pos loc . Location . loc_start before < 0 && Lexing . compare_pos loc . Location . loc_end before > 0 ) trie with | None -> log ~ title " : find " " didn ' t find anything " ; follow ~ state... |
type context = | Initial of Lexing . position | Resume of state |
let rec dump fmt trie = let open Trie in let rec dump_node fmt = function | Leaf -> ( ) | Included Named path -> Format . fprintf fmt " <% s " > ( Namespaced_path . to_string path ) | Alias path -> Format . fprintf fmt " = % s " ( Namespaced_path . to_string path ) | Included Items t | Internal t -> if Lazy . is_val t ... |
let find ~ remember_loc ~ context trie path = match context with | Initial before -> log ~ title " : initial find " " before % s , trie : % a " ( Lexing . print_position ( ) before ) Logger . fmt ( fun fmt -> dump fmt trie ) ; find ~ remember_loc ~ before [ ] trie path | Resume state -> follow ~ remember_loc ~ state [ ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.