text
stringlengths
12
786k
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_e...
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 s...
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 ...
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 |> Re...
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 ....
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...
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 . o...
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 : ...
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 ....
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 m...
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 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...
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...
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 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_envi...
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 ( Unannotat...
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 . ...
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 >>| Unan...
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 |> UnannotatedGlobalEnv...
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 ScratchPro...
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 . ...
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 " , depe...
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...
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 " ...
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 ) ...
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 ; ex...
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_resolv...
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 : co...
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 } -> ...
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...
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 * alide...
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 " , [ " UnassignIpv6Addres...
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...
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 | N...
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 ; } } ] ; ; |
type a = { a : b } [ @@ unboxed ]
let rec a = { a = ( if Sys . opaque_identity true then X a else Y ) } ; ; [ %% expect { |
type a = { a : b ; } [ @@ unboxed ] } ] ; ; |
type d = D of e [ %% expect { |
type d = D of e } ] ; ; |
let rec d = D ( if Sys . opaque_identity true then V d else W ) ; ; [ %% expect { | } ] ; ; |
type d = D of e [ @@ unboxed ]
let rec d = D ( if Sys . opaque_identity true then V d else W ) ; ; [ %% expect { |
type d = D of e [ @@ unboxed ] } ] ; ; |
module Transform = struct let pass_name = " unbox - closures " let precondition ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = ! Clflags . unbox_closures && not ( E . at_toplevel env ) && not ( Variable . Map . is_empty set_of_closures . free_vars ) let what_to_specialis...
let ( ) = Pass_wrapper . register ~ pass_name
let add_lifted_projections_around_set_of_closures ~ set_of_closures ~ existing_inner_to_outer_vars ~ benefit ~ definitions_indexed_by_new_inner_vars = let body = Flambda_utils . name_expr ( Set_of_closures set_of_closures ) ~ name : Internal_variable_names . unbox_free_vars_of_closures in Variable . M...
let run ~ env ( ~ set_of_closures : Flambda . set_of_closures ) = if not ! Clflags . unbox_free_vars_of_closures then None else let definitions_indexed_by_new_inner_vars , _ , free_vars , done_something = let all_existing_definitions = Variable . Map . fold ( fun _inner_var ( outer_var :...
let run ~ env ~ set_of_closures = Pass_wrapper . with_dump ~ ppf_dump ( : Inline_and_simplify_aux . Env . ppf_dump env ) ~ pass_name ~ input : set_of_closures ~ print_input : Flambda . print_set_of_closures ~ print_output ( : fun ppf ( expr , _ ) -> Flambda . print ppf expr ) ~ f ...
module Transform = struct let pass_name = " unbox - specialised - args " let precondition ~ env : _ ( ~ set_of_closures : Flambda . set_of_closures ) = ! Clflags . unbox_specialised_args && not ( Variable . Map . is_empty set_of_closures . specialised_args ) let what_to_specialise ~ e...
module Float = struct type _ t = | IO : int option t | F : float t let bar : type a . a t -> float -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : float t ) f i = let r = ref 0 . in r := bar t f i end
module Int32 = struct type _ t = | IO : int option t | F : int32 t let bar : type a . a t -> int32 -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : int32 t ) f i = let r = ref 0l in r := bar t f i end
module Int64 = struct type _ t = | IO : int option t | F : int64 t let bar : type a . a t -> int64 -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : int64 t ) f i = let r = ref 0L in r := bar t f i end
module Nativeint = struct type _ t = | IO : int option t | F : nativeint t let bar : type a . a t -> nativeint -> int -> a = fun t f i -> match t with | IO -> Some i | F -> f [ @@ inline always ] let foo ( t : nativeint t ) f i = let r = ref 0n in r := bar t f i end
let kasprintf k fmt = Format . ( kfprintf ( fun _ -> k ( flush_str_formatter ( ) ) ) str_formatter fmt )
let invalid_arg fmt = kasprintf invalid_arg ( " Nocrypto : " ^^ fmt )
let failwith fmt = kasprintf failwith ( " Nocrypto : " ^^ fmt )
let ( ) // x y = if y < 1 then raise Division_by_zero else if x > 0 then 1 + ( ( x - 1 ) / y ) else 0 [ @@ inline ]
let imin ( a : int ) b = if a < b then a else b
let imax ( a : int ) b = if a < b then b else a
let ( . ) & f g = fun h -> f ( g h )
let id x = x
let rec until p f = let r = f ( ) in if p r then r else until p f
module Option = struct let get_or f x = function None -> f x | Some y -> y let ( ) >>= a fb = match a with Some x -> fb x | _ -> None let ( ) >>| a f = match a with Some x -> Some ( f x ) | _ -> None let v_map ~ def ~ f = function | Some x -> f x | None -> def let get ~ def = funct...
type ' a iter = ( ' a -> unit ) -> unit
let iter1 a f = f a
let iter2 a b f = f a ; f b
let iter3 a b c f = f a ; f b ; f c
let string_fold ~ f ~ z str = let st = ref z in ( String . iter ( fun c -> st := f ! st c ) str ; ! st )
module Z = struct include Z let two = ~$ 2 let three = ~$ 3 let pp = pp_print open Sexplib . Conv let sexp_of_t z = sexp_of_string ( Z . to_string z ) let t_of_sexp s = Z . of_string ( string_of_sexp s ) end
module Cs = struct open Cstruct let empty = create 0 let null cs = len cs = 0 let ( ) <+> = append let ct_eq cs1 cs2 = let rec go ok i = function | n when n >= 8 -> go ( LE . ( get_uint64 cs1 i = get_uint64 cs2 i ) && ok ) ( i + 8 ) ( n - 8 ) | n when n >= 4 -> go ( LE . ...
module Array = struct include Array let mem x arr = let rec scan = function | - 1 -> false | n -> arr . ( n ) = x || scan ( pred n ) in scan ( Array . length arr - 1 ) end