text
stringlengths
0
601k
module type Type = sig type text class input_line : UChar . t # obj_input_channel -> [ text ] text obj_input_channel class output_line : ? sp [ ` : CR | ` CRLF | ` LF | ` LS | ` NEL | ` PS ] PS -> UChar . t # obj_output_channel -> [ text ] text obj_output_channel end
module Make ( Text : UnicodeString . Type ) Type = struct type text = Text . t class input_line inchan = object val b = Text . Buf . create 0 val mutable wait = false method get ( get ) get = Text . Buf . clear b ; let rec loop ( ) = let x = wait in wait <- false ; match UChar . uint_code ( inchan # get ( get ) get ) g...
let umap_of_imap m = m
let imap_of_umap m = m
let add ? eq u v m = IMap . add ? eq ( UChar . uint_code u ) u v m
let add_range ? eq u1 u2 v m = IMap . add_range ? eq ( UChar . uint_code u1 ) u1 ( UChar . uint_code u2 ) u2 v m
let find u m = IMap . find ( UChar . uint_code u ) u m
let remove u m = IMap . remove ( UChar . uint_code u ) u m
let remove_range u1 u2 m = IMap . remove_range ( UChar . uint_code u1 ) u1 ( UChar . uint_code u2 ) u2 m
let from u m = IMap . from ( UChar . uint_code u ) u m
let after u m = IMap . after ( UChar . uint_code u ) u m
let until u m = IMap . until ( UChar . uint_code u ) u m
let before u m = IMap . before ( UChar . uint_code u ) u m
let mem u m = IMap . mem ( UChar . uint_code u ) u m
let iter f m = let f ' n = f ( UChar . chr_of_uint n ) n in IMap . iter f ' m
let iter_range f m = let f ' n1 n2 = f ( UChar . chr_of_uint n1 ) n1 ( UChar . chr_of_uint n2 ) n2 in IMap . iter_range f ' m
let fold f m a = let f ' n v a = f ( UChar . chr_of_uint n ) n v a in IMap . fold f ' m a
let fold_range f m a = let f ' n1 n2 v a = f ( UChar . chr_of_uint n1 ) n1 ( UChar . chr_of_uint n2 ) n2 v a in IMap . fold_range f ' m a
let mapi ? eq f m = let f ' n v = f ( UChar . chr_of_uint n ) n v in IMap . mapi ? eq f ' m
let set_to_map s = IMap . set_to_map ( USet . iset_of_uset s ) s
let domain m = USet . uset_of_iset ( IMap . domain m ) m
let map_to_set p m = USet . uset_of_iset ( IMap . map_to_set p m ) m
module UnannotatedDefine = struct type t = { define : Define . Signature . t ; location : Location . WithModule . t ; } [ @@ deriving sexp , compare ] end
module ImportEntry = struct type t = | Module of { target : Reference . t ; implicit_alias : bool ; } | Name of { from : Reference . t ; target : Identifier . t ; implicit_alias : bool ; } [ @@ deriving sexp , compare ] let deprecated_original_name = function | Module { target ; implicit_alias } -> if implicit_alias th...
type t = | SimpleAssign of { explicit_annotation : Expression . t option ; value : Expression . t ; target_location : Location . WithModule . t ; } | TupleAssign of { value : Expression . t ; target_location : Location . WithModule . t ; index : int ; total_length : int ; } | Imported of ImportEntry . t | Define of Una...
module Collector = struct module Result = struct type unannotated_global = t [ @@ deriving sexp , compare ] type t = { name : Identifier . t ; unannotated_global : unannotated_global ; } [ @@ deriving sexp , compare ] end let from_source { Source . statements ; source_path = { ModulePath . qualifier ; _ } ; _ } = let r...
module ResolvedReference = struct type export = | FromModuleGetattr | Exported of Module . Export . Name . t [ @@ deriving sexp , compare , hash ] type t = | Module of Reference . t | ModuleAttribute of { from : Reference . t ; name : Identifier . t ; export : export ; remaining : Identifier . t list ; } | PlaceholderS...
let missing_builtin_globals = let assign name annotation = { UnannotatedGlobal . Collector . Result . name ; unannotated_global = UnannotatedGlobal . SimpleAssign { explicit_annotation = Some ( Type . expression annotation ) ; target_location = Location . WithModule . any ; value = Node . create_with_default_location (...
let missing_builtin_classes , missing_typing_classes , missing_typing_extensions_classes = let make ( ? bases = [ ] ) ( ? metaclasses = [ ] ) ( ? body = [ ] ) name = let create_base annotation = { Call . Argument . name = None ; value = Type . expression annotation } in let create_metaclass annotation = { Call . Argume...
module KeyTracker = struct module ClassKeyValue = struct type t = Identifier . t list [ @@ deriving compare ] let prefix = Prefix . make ( ) let description = " Class keys " end module DefineKeyValue = struct type t = Reference . t list [ @@ deriving compare ] let prefix = Prefix . make ( ) let description = " Define k...
module ModuleValue = struct type t = Module . t let prefix = Prefix . make ( ) let description = " Module " let compare = Module . compare end
module Modules = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . ReferenceKey ) ( DependencyKey ) ( ModuleValue ) let is_qualifier = true let key_to_reference = Fn . id end
module ClassSummaryValue = struct type t = ClassSummary . t Node . t let prefix = Prefix . make ( ) let description = " ClassSummary " let compare = Node . compare ClassSummary . compare end
module ClassSummaries = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . StringKey ) ( DependencyKey ) ( ClassSummaryValue ) let is_qualifier = false let key_to_reference name = Reference . create name end
module FunctionDefinitionValue = struct type t = FunctionDefinition . t let description = " FunctionDefinition " let prefix = Prefix . make ( ) let compare = FunctionDefinition . compare end
module FunctionDefinitions = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . ReferenceKey ) ( DependencyKey ) ( FunctionDefinitionValue ) let is_qualifier = false let key_to_reference = Fn . id end
module UnannotatedGlobalValue = struct type t = UnannotatedGlobal . t let prefix = Prefix . make ( ) let description = " UnannotatedGlobal " let compare = UnannotatedGlobal . compare end
module UnannotatedGlobals = struct include DependencyTrackedMemory . DependencyTrackedTableNoCache ( SharedMemoryKeys . ReferenceKey ) ( DependencyKey ) ( UnannotatedGlobalValue ) let is_qualifier = false let key_to_reference = Fn . id end
module ReadWrite = struct type t = { key_tracker : KeyTracker . t ; modules : Modules . t ; class_summaries : ClassSummaries . t ; function_definitions : FunctionDefinitions . t ; unannotated_globals : UnannotatedGlobals . t ; ast_environment : AstEnvironment . t ; } let create ast_environment = { key_tracker = KeyTrac...
let set_module { modules ; _ } ~ qualifier module_ = Modules . add modules qualifier module_
let set_class_summary { class_summaries ; _ } ~ name class_summary = ClassSummaries . write_around class_summaries name class_summary
let set_function_definition { function_definitions ; _ } ~ name function_definition = FunctionDefinitions . write_around function_definitions name function_definition
let set_unannotated_global { unannotated_globals ; _ } ~ name unannotated_global = UnannotatedGlobals . add unannotated_globals name unannotated_global
let set_class_summaries ( { key_tracker ; _ } as environment ) ( { Source . source_path = { ModulePath . qualifier ; _ } ; _ } as source ) = let module ClassCollector = Visit . MakeStatementVisitor ( struct type t = Class . t Node . t list let visit_children _ = true let statement _ sofar = function | { Node . location...
let set_function_definitions ( { key_tracker ; _ } as environment ) ( { Source . source_path = { ModulePath . qualifier ; is_external ; _ } ; _ } as source ) = match is_external with | true -> ( ) | false -> let function_definitions = FunctionDefinition . collect_defines source in let register ( name , function_definit...
let set_unannotated_globals ( { key_tracker ; _ } as environment ) ( { Source . source_path = { ModulePath . qualifier ; _ } ; _ } as source ) = let write { UnannotatedGlobal . Collector . Result . name ; unannotated_global } = let name = Reference . create name |> Reference . combine qualifier in set_unannotated_globa...
let set_module_data environment ( { Source . source_path = { ModulePath . qualifier ; _ } ; _ } as source ) = set_class_summaries environment source ; set_function_definitions environment source ; set_unannotated_globals environment source ; set_module environment ~ qualifier ( Module . create source )
let add_to_transaction { modules ; class_summaries ; function_definitions ; unannotated_globals ; _ } transaction ~ previous_classes_list ~ previous_unannotated_globals_list ~ previous_defines_list ~ previous_modules_list = let module_keys = Modules . KeySet . of_list previous_modules_list in let class_keys = ClassSumm...
let get_all_dependents ~ class_additions ~ unannotated_global_additions ~ define_additions = let function_and_class_dependents = DependencyKey . RegisteredSet . union ( ClassSummaries . KeySet . of_list class_additions |> ClassSummaries . get_all_dependents ) ( FunctionDefinitions . KeySet . of_list define_additions |>...
module ReadOnly = struct type t = { ast_environment : AstEnvironment . ReadOnly . t ; class_exists : ? dependency : DependencyKey . registered -> string -> bool ; all_classes : unit -> Type . Primitive . t list ; all_indices : unit -> IndexTracker . t list ; all_unannotated_globals : unit -> Reference . t list ; all_de...
module LazyLoader = struct type t = { environment : ReadWrite . t ; ast_environment : AstEnvironment . ReadOnly . t ; } let load_module_if_tracked { environment ; ast_environment } qualifier = if not ( Modules . mem environment . modules qualifier ) then if AstEnvironment . ReadOnly . is_module_tracked ast_environment ...
module ReadOnlyTable = struct module type S = sig type key type value type table type t val create : loader : LazyLoader . t -> table -> t val mem : t -> ? dependency : DependencyKey . registered -> key -> bool val get : t -> ? dependency : DependencyKey . registered -> key -> value option end module type In = sig type...
let read_only ( { ast_environment ; key_tracker ; modules ; class_summaries ; function_definitions ; unannotated_globals ; } as environment ) = let ast_environment = AstEnvironment . read_only ast_environment in let loader = LazyLoader . { environment ; ast_environment } in let module Modules = ReadOnlyTable . Make ( M...
module UpdateResult = struct type t = { previous_classes : Type . Primitive . Set . t ; previous_defines : Reference . Set . t ; define_additions : Reference . Set . t ; previous_unannotated_globals : Reference . Set . t ; triggered_dependencies : DependencyKey . RegisteredSet . t ; invalidated_modules : AstEnvironment...
let cold_start ( { ast_environment ; _ } as environment ) = let ast_read_only = AstEnvironment . read_only ast_environment in AstEnvironment . ReadOnly . get_processed_source ast_read_only ~ track_dependency : true Reference . empty >>| set_module_data environment |> Option . value ~ default ( ) ; : read_only environme...
let update_this_and_all_preceding_environments ( { ast_environment ; key_tracker ; _ } as environment ) ~ scheduler trigger = let invalidated_modules = AstEnvironment . update ~ scheduler ast_environment trigger in let ast_environment = AstEnvironment . read_only ast_environment in let map sources = let register qualif...
let location ( start_line , start_column ) ( stop_line , stop_column ) = { Location . start = { Location . line = start_line ; column = start_column } ; stop = { Location . line = stop_line ; column = stop_column } ; }
let create_with_location value start end_ = Node . create value ~ location ( : location start end_ )
let create_and_cold_start project = let ast_environment = ScratchProject . build_ast_environment project in let unannotated_global_environment = UnannotatedGlobalEnvironment . create ast_environment in let _ = UnannotatedGlobalEnvironment . cold_start unannotated_global_environment in unannotated_global_environment
let test_global_registration context = let assert_registers ( ? expected = true ) source name = let project = ScratchProject . setup [ " test . py " , source ] ~ context in let read_only = create_and_cold_start project |> UnannotatedGlobalEnvironment . read_only in assert_equal ( UnannotatedGlobalEnvironment . ReadOnly...
let test_define_registration context = let assert_registers ~ expected source = let project = ScratchProject . setup [ " test . py " , source ] ~ context in let read_only = create_and_cold_start project |> UnannotatedGlobalEnvironment . read_only in let actual = UnannotatedGlobalEnvironment . ReadOnly . all_defines_in_...
let test_simple_global_registration context = let assert_registers source name expected = let project = ScratchProject . setup [ " test . py " , source ] ~ context in let read_only = create_and_cold_start project |> UnannotatedGlobalEnvironment . read_only in let printer global = global >>| UnannotatedGlobal . sexp_of_...
let test_builtin_modules context = let read_only = let sources = [ " builtins . py " , " foo : int = 42 " ] in let project = ScratchProject . setup ~ context ~ include_typeshed_stubs : false ~ include_helper_builtins : false sources in create_and_cold_start project |> UnannotatedGlobalEnvironment . read_only in assert_...
let test_resolve_exports context = let open UnannotatedGlobalEnvironment in let assert_resolved ( ? include_typeshed = false ) ~ expected ? from ~ reference sources = Memory . reset_shared_memory ( ) ; let project = if include_typeshed then ScratchProject . setup ~ context sources else ScratchProject . setup ~ context ...
let assert_updates ~ context ? original_source ? new_source ~ middle_actions ~ expected_triggers ? post_actions ( ) = Memory . reset_shared_memory ( ) ; let sources = original_source >>| ( fun source -> " test . py " , source ) |> Option . to_list in let project = ScratchProject . setup ~ include_typeshed_stubs : false...
let type_check_dependency = SharedMemoryKeys . DependencyKey . Registry . register ( TypeCheckDefine ( Reference . create " test " ) )
let alias_dependency = SharedMemoryKeys . DependencyKey . Registry . register ( TypeCheckDefine ( Reference . create " dep " ) )
let test_get_class_summary context = let assert_updates = assert_updates ~ context in let dependency = type_check_dependency in assert_updates ~ original_source { :| class Foo : x : int } | ~ new_source { :| class Foo : x : str } | ~ middle_actions [ ` : Get ( " test . Foo " , dependency , Some 1 ) ] ~ expected_trigger...
let test_class_exists_and_all_classes context = let assert_updates = assert_updates ~ context in let dependency = type_check_dependency in assert_updates ~ new_source { :| class Foo : x : int } | ~ middle_actions [ ` : Mem ( " test . Foo " , dependency , false ) ] ~ expected_triggers [ : dependency ] ( ) ; assert_updat...
let test_get_unannotated_global context = let assert_updates = assert_updates ~ context in let dependency = alias_dependency in assert_updates ~ original_source { :| x : int = 7 } | ~ new_source { :| x : int = 9 } | ~ middle_actions : [ ` Global ( Reference . create " test . x " , dependency , Some ( UnannotatedGlobal ...
let test_dependencies_and_new_values context = let assert_updates = assert_updates ~ context in assert_updates ~ original_source { :| class Foo : x : int } | ~ new_source { :| class Foo : 2376 x : str } | ~ middle_actions : [ ` Get ( " test . Foo " , alias_dependency , Some 1 ) ; ` Get ( " test . Foo " , type_check_dep...
let test_get_define_body context = let assert_updates = assert_updates ~ context in let dependency = type_check_dependency in let open Statement in let open Expression in let create_simple_return ~ start ~ stop expression = node ~ start ~ stop ( Statement . Return { Return . is_implicit = false ; expression = Some expr...
let ( ) = " environment " >::: [ " global_registration " >:: test_global_registration ; " define_registration " >:: test_define_registration ; " simple_globals " >:: test_simple_global_registration ; " builtins " >:: test_builtin_modules ; " resolve_exports " >:: test_resolve_exports ; " get_class_summary " >:: test_ge...
let test_collection context = let assert_collected_names ~ expected source_text = let source = parse ~ handle " : test . py " source_text in let actual = Collector . from_source source |> List . map ~ f ( : fun { Collector . Result . name ; _ } -> name ) in assert_equal ~ ctxt : context ~ cmp [ :% compare . equal : str...
let test_import context = let assert_imports ~ expected source_text = let source = parse ~ handle " : test . py " source_text in let actual = Collector . from_source source |> List . filter_map ~ f ( : function | { Collector . Result . name ; unannotated_global = Imported import } -> Some ( name , import ) | _ -> None ...
let ( ) = " node " >::: [ " collection " >:: test_collection ; " import " >:: test_import ] |> Test . run
type loc = FanLoc . t ; type ant = [ ` Ant of ( loc * FanUtil . anti_cxt ) ] ; type nil = [ ` Nil of loc ] ; type ant_nil = [ ant | nil ] ; type literal = [ ` Chr of ( loc * string ) | ` Int of ( loc * string ) | ` Int32 of ( loc * string ) | ` Int64 of ( loc * string ) | ` Flo of ( loc * string ) | ` Nativeint of ( lo...
type pat = [ nil | sid | ` App of ( loc * pat * pat ) | ` Vrn of ( loc * string ) | ` Com of ( loc * pat * pat ) | ` Sem of ( loc * pat * pat ) | ` Par of ( loc * pat ) | any | ` Record of ( loc * rec_pat ) | ant | literal | ` Alias of ( loc * pat * alident ) | ` Array of ( loc * pat ) | ` Label of ( loc * alident * pa...
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " UnassignIpv6Addresses " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . ...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UnassignIpv6AddressesResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UnassignIpv6AddressesResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UnassignIpv6Addresses...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
type synonym = ' a -> ' a [ %% expect { | ^^ } ] |
type record = { contents : ' a } [ %% expect { | ^^ } ] |
type wrapper = Wrapper of ' a [ %% expect { | ^^ } ] |
type polyvariant = [ > ` C ] [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^ In type [ > ` C ] as ' a the variable ' a is unbound } ] |
type ' a only_one = ' a * ' b [ %% expect { | ^^ } ] |
type extensible += Extension of ' a [ %% expect { |
type extensible = . . ^^ } ] |
type r = R of r list [ @@ unboxed ]
let rec a = R [ a ] ; ; [ %% expect { |
type r = R of r list [ @@ unboxed ] } ] ; ; |
type t = { x : int64 } [ @@ unboxed ]
let rec x = { x = y } and y = 3L ; ; [ %% expect { |
type t = { x : int64 ; } [ @@ unboxed ] ^^^^^^^ } ] ; ; |
type r = A of r [ @@ unboxed ]
let rec y = A y ; ; [ %% expect { |
type r = A of r [ @@ unboxed ] ^^^ } ] ; ; |
type a = { a : b }
let rec a = { a = ( if Sys . opaque_identity true then X a else Y ) } ; ; [ %% expect { |
type a = { a : b ; } } ] ; ; |