text
stringlengths
12
786k
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 ...
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...
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 ...
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...
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...
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_...
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 cam...
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 ...
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...
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_wit...
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 * Lon...
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 , _ ) -> L...
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 ) ...
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 -> shall...
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 ...
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 ...
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 : expr...
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_ty...
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_sign...
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 : extens...
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 . ...
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 ent...
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 | Fun...
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_exp...
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 ) = Type...
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 ...
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_pr...
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 " ...
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 It...
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 | Re...
type uint32 = float object method byteLength : int readonly_prop method slice : int -> int -> arrayBuffer t meth method slice_toEnd : int -> arrayBuffer t meth end
let arrayBuffer : ( int -> arrayBuffer t ) constr = Js . Unsafe . global . ## _ArrayBuffer object method buffer : arrayBuffer t readonly_prop method byteOffset : int readonly_prop method byteLength : int readonly_prop end object inherit arrayBufferView method _BYTES_PER_ELEMENT : int readonly_prop m...
type int8Array = ( int , Bigarray . int8_signed_elt ) typedArray
type uint8Array = ( int , Bigarray . int8_unsigned_elt ) typedArray
type int16Array = ( int , Bigarray . int16_signed_elt ) typedArray
type uint16Array = ( int , Bigarray . int16_unsigned_elt ) typedArray
type int32Array = ( int32 , Bigarray . int32_elt ) typedArray
type uint32Array = ( int32 , Bigarray . int32_elt ) typedArray
type float32Array = ( float , Bigarray . float32_elt ) typedArray
type float64Array = ( float , Bigarray . float64_elt ) typedArray = " caml_ba_kind_of_typed_array " ( ' a , ' b , Bigarray . c_layout ) Bigarray . Genarray . t -> ( ' a , ' b ) typedArray t = " caml_ba_to_typed_array " ( ' a , ' b ) typedArray t -> ( ' a , ...
let set : ( ' a , ' b ) typedArray t -> int -> ' a -> unit = fun a i v -> array_set ( Unsafe . coerce a ) i v
let get : ( ' a , ' b ) typedArray t -> int -> ' a optdef = fun a i -> Js . Unsafe . get a i
let unsafe_get : ( ' a , ' b ) typedArray t -> int -> ' a = fun a i -> Js . Unsafe . get a i object inherit arrayBufferView method getInt8 : int -> int meth method getUint8 : int -> int meth method getInt16 : int -> int meth method getInt16_ : int -> bool t -> int meth method getUint16 : ...
module Bigstring = struct type t = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) Bigarray . Array1 . t external to_arrayBuffer : t -> arrayBuffer Js . t = " bigstring_to_array_buffer " external to_uint8Array : t -> uint8Array Js . t = " bigstring_to_typed_array " exte...
module String = struct external of_uint8Array : uint8Array Js . t -> string = " caml_string_of_array " let of_arrayBuffer ab = let uint8 = new % js uint8Array_fromBuffer ab in of_uint8Array uint8 end
module AnalysisErrorValue = struct type t = Error . t list let prefix = Prefix . make ( ) let description = " Raw analysis errors " end
module LocalAnnotationsValue = struct type t = LocalAnnotationMap . ReadOnly . t let prefix = Prefix . make ( ) let description = " Node type resolution " end
module RawErrors = Memory . FirstClass . NoCache . Make ( SharedMemoryKeys . ReferenceKey ) ( AnalysisErrorValue )
module LocalAnnotations = Memory . FirstClass . WithCache . Make ( SharedMemoryKeys . ReferenceKey ) ( LocalAnnotationsValue )
type t = { global_environment : AnnotatedGlobalEnvironment . t ; set_errors : Reference . t -> Error . t list -> unit ; set_local_annotations : Reference . t -> LocalAnnotationMap . ReadOnly . t -> unit ; invalidate : Reference . t list -> unit ; get_errors : Reference . t -> Error...
let global_environment { global_environment ; _ } = global_environment
let ast_environment { global_environment ; _ } = AnnotatedGlobalEnvironment . ast_environment global_environment
let module_tracker type_environment = ast_environment type_environment |> AstEnvironment . module_tracker
let set_errors { set_errors ; _ } = set_errors
let get_errors { get_errors ; _ } = get_errors
let set_local_annotations { set_local_annotations ; _ } = set_local_annotations
let get_local_annotations { get_local_annotations ; _ } = get_local_annotations
let invalidate { invalidate ; _ } = invalidate
let create global_environment = let raw_errors = RawErrors . create ( ) in let local_annotations = LocalAnnotations . create ( ) in let get_errors reference = RawErrors . get raw_errors reference |> Option . value ~ default [ ] : in let set_errors = RawErrors . add raw_errors in let get_lo...
module ReadOnly = struct type t = { global_environment : AnnotatedGlobalEnvironment . ReadOnly . t ; get_errors : Reference . t -> Error . t list ; get_local_annotations : Reference . t -> LocalAnnotationMap . ReadOnly . t option ; } let create ( ? get_errors = fun _ -> [ ] ) ...
let read_only { global_environment ; get_errors ; get_local_annotations ; _ } = ReadOnly . create ~ get_errors ~ get_local_annotations ( AnnotatedGlobalEnvironment . read_only global_environment )
let test_type_guard context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_default_type_errors { | from typing import Any , List , TypeGuard def is_str_list ( val : List [ Any ] ) -> TypeGuard [ List [ ...
let test_multiple_arguments context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | from typing import TypeGuard , List def is_str_list ( val : List [ int | str ] , allow_empty : bool ) -> ...
let test_methods context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import List , TypeGuard class Foo : def is_str_list ( self , val : List [ int | str ] ) -> TypeGuard [ List [ str ] ] : return all ( isinstance ( x , str ) for x ...
let test_callback context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | from typing import Callable , TypeGuard def simple_fn ( x : bool , is_int : Callable [ [ object ] , TypeGuard [ i...
let test_return_type context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | from typing import List , TypeGuard def is_str_list ( val : List [ int | str ] ) -> TypeGuard [ List [ str ] ...
let test_walrus_operator context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeGuard def typeguard_fn ( val : int | str ) -> TypeGuard [ int ] : return True def foo ( x : int | str ) -> None : if typeguard_fn ( bar := x ) : revea...