text stringlengths 12 786k |
|---|
module Tp = Unify ; ; |
module Main ( C : V1_LWT . CONSOLE ) ( S : V1_LWT . STACKV4 ) = struct module Session = Session . Tcp ( S ) let horseos = Horse_manager . create let start c s = let log message = C . log c message in let rec listen_input session username = Session . read session ( Horse_manager . bro... |
module type Type = sig type mapping val read_map : mapping -> int -> int type mapping_rw val create_mapping_rw : int -> mapping_rw val mapping_rw_to_ro : mapping_rw -> mapping val add_mapping : mapping_rw -> int -> int -> unit type t = { enc_to_ucs : mapping ; ucs_to_enc : mapping ; } type rw = ... |
module Make ( Config : ConfigInt . Type ) Type : Type = struct type mapping = { no_char : int ; tbl : Tbl31 . Bytes . t } t let read_map map i = Tbl31 . Bytes . get map . tbl i type mapping_rw = { rw_no_char : int ; mutable rw_tbl : int IMap . t } t let create_mapping_rw no_char = {... |
module Spec = struct include Analyses . DefaultSpec module Addr = ValueDomain . Addr module D = ValueDomain . AddrSetDomain module C = ValueDomain . AddrSetDomain type trans_in = D . t type trans_out = D . t type transfer = trans_in -> trans_out let name ( ) = " uninit " let should_join x y... |
let _ = MCP . register_analysis ( module Spec : MCPSpec ) |
module NameAccessSet = Set . Make ( Define . NameAccess ) |
module AccessCollector = struct let rec from_expression collected { Node . value ; location = expression_location } = let open Expression in let from_entry collected { Dictionary . Entry . key ; value } = let collected = from_expression collected key in from_expression collected value in match va... |
let extract_reads_in_expression expression = let name_access_to_identifier_node { Define . NameAccess . name ; location } = { Node . value = name ; location } in AccessCollector . from_expression NameAccessSet . empty expression |> NameAccessSet . to_list |> List . map ~ f : name_access... |
let extract_reads_in_statement { Node . value ; _ } = let expressions = match value with | Statement . Assign { Assign . value = expression ; _ } | Expression expression | If { If . test = expression ; _ } | While { While . test = expression ; _ } -> [ expression ] |... |
type defined_locals = Scope . Binding . t Identifier . Map . t |
let create_map = List . fold ~ init : Identifier . Map . empty ~ f ( : fun sofar ( { Scope . Binding . name ; _ } as binding ) -> Map . set sofar ~ key ( : Identifier . sanitized name ) ~ data : binding ) |
module type Context = sig val fixpoint_post_statement : ( Statement . t * defined_locals ) StatementKey . Table . t end |
module State ( Context : Context ) = struct type t = | Bottom | Value of defined_locals let show = function | Bottom -> " [ ] " | Value state -> let show_binding { Scope . Binding . name ; location ; _ } = [ % show : Identifier . t * Location . t ] ( name , location ) ... |
let defined_locals_at_each_statement define = let module Context = struct let fixpoint_post_statement = StatementKey . Table . create ( ) end in let module State = State ( Context ) in let module Fixpoint = Fixpoint . Make ( State ) in let cfg = Cfg . create ( Node . value define ) in le... |
let errors ~ qualifier ~ define defined_locals_at_each_statement = let emit_error { Node . value ; location } = Error . create ~ location ( : Location . with_module ~ module_reference : qualifier location ) ~ kind ( : Error . UninitializedLocal value ) ~ define in let all_locals = let ... |
let run_on_define ~ qualifier define = defined_locals_at_each_statement define |> errors ~ qualifier ~ define |
let run ~ configuration : _ ~ environment : _ ~ source ( { : Source . source_path = { ModulePath . qualifier ; _ } ; _ } as source ) = source |> Preprocessing . defines ~ include_toplevels : false |> List . map ~ f ( : run_on_define ~ qualifier ) |> List . concat |
let assert_uninitialized_errors ~ context = let check ~ configuration ~ environment ~ source = UninitializedLocalCheck . run ~ configuration ~ environment ( : TypeEnvironment . read_only environment ) ~ source in assert_errors ~ context ~ check |
let test_simple context = let assert_uninitialized_errors = assert_uninitialized_errors ~ context in assert_uninitialized_errors { | def f ( ) : x = y y = 5 } | [ " Uninitialized local [ 61 ] : Local variable ` y ` is undefined , or not always defined . " ] ; assert_uninitialize... |
let test_cfg context = let assert_uninitialized_errors = assert_uninitialized_errors ~ context in assert_uninitialized_errors { | def f ( ) : if True : x = 1 else : raise AssertionError ( " error " ) return x def g ( ) : if True : y = 1 else : assert False , " error " return y def ... |
let assert_defined_locals source expected = let define = parse_single_define source in let open Statement in let open Expression in let open UninitializedLocalCheck in let actual_defined_locals = define |> Node . create_with_default_location |> defined_locals_at_each_statement in let sanitize_for_tests statement... |
let test_defined_locals_at_each_statement _ = assert_defined_locals { | def f ( ) : if True : x = 1 else : raise AssertionError ( " error " ) return x } | [ { | x = 1 } , | [ " x " , " 4 : 4 - 4 : 5 " ] ; { | raise AssertionError ( " error " ) } ,... |
let ( ) = " uninitializedCheck " >::: [ " simple " >:: test_simple ; " cfg " >:: test_cfg ; " defined_locals_at_each_statement " >:: test_defined_locals_at_each_statement ; ] |> Test . run |
let ocaml_config = get_command_output " ocamlc - config " |
let is_mingw = List . exists ( ( ) = " system : mingw " ) ocaml_config |
let prefix = ref ( if is_mingw then begin let re = Str . regexp " : " in let conf = List . map ( fun l -> match Str . split re l with [ n ; v ] -> n , v | [ n ] -> n , " " | _ -> assert false ) ocaml_config in let lib = List . assoc " standard_library " conf in Filena... |
let ver_1_8_0 = ref false |
let ext = if is_win32 then " . exe " else " " |
let uninstall ( ) = if not is_win32 then begin if ! ver_1_8_0 then begin kprintf run " rm - vfr % s / share / pixmaps / ocamleditor " ! prefix ; kprintf run " rm - vf % s / bin / ocamleditor " ! prefix ; kprintf run " rm - vf % s / bin / oebuild % s " ! prefix ext ; kprintf run ... |
let _ = main ~ default_target : uninstall ~ options [ : " - prefix " , Set_string prefix , ( sprintf " Installation prefix ( default is % s ) " ! prefix ) ; " - ver - 1 . 8 . 0 " , Set ver_1_8_0 , ( sprintf " Uninstall OCamlEditor version 1 . 8 . 0 " ) ; ... |
module MyQuery = [ % graphql { | { dogOrHuman { . . . on Dog { name barkVolume } . . . on Human { name } } } } ] | |
let pp formatter ( obj : qt ) = Format . fprintf formatter " < dogOrHuman = % a " > ( fun formatter -> function | ` FutureAddedValue _ -> Format . fprintf formatter " ` FutureAddedValue " | ` Dog ( dog : MyQuery . t_dogOrHuman_Dog ) -> Format . fprintf formatter " ` Dog ... |
let equal ( a : qt ) ( b : qt ) = match ( a . dogOrHuman , b . dogOrHuman ) with | ` Dog a , ` Dog b -> a . name = b . name && a . barkVolume = b . barkVolume | ` Human a , ` Human b -> a . name = b . name | _ -> false |
let decodes_exhaustive_query ( ) = test_exp ( { | { " dogOrHuman " : { " __typename " : " Dog " , " name " : " Fido " , " barkVolume " : 123 . 0 } } } | |> Json . Read . from_string |> MyQuery . unsafe_fromJson |> MyQuery . parse ) { dogOrHuman =... |
let tests = [ ( " Decodes exhaustive query " , decodes_exhaustive_query ) ] |
let ml_declaration oc ud = if ud . ud_name = " " then fprintf oc " union_ % d =\ n " ud . ud_stamp else fprintf oc " % s =\ n " ( String . uncapitalize_ascii ud . ud_name ) ; let out_constr oc c = if c = " default " then if ud . ud_name <> " " then fprintf oc " Default_ %... |
let c_declaration oc ud = if ud . ud_cases = [ ] then fprintf oc " union % s ; \ n " ud . ud_name else begin out_union oc ud ; fprintf oc " ; \ n \ n " end |
let declare_transl oc ud = fprintf oc " extern int camlidl_ml2c_ % s_union_ % s ( value , union % s , * camlidl_ctx _ctx ) ; \ n " ud . ud_mod ud . ud_name ud . ud_name ; fprintf oc " extern value camlidl_c2ml_ % s_union_ % s ( int , union % s , * camlidl_ctx _ctx ) ; \ n ... |
let transl_ml_to_c oc ud = current_function := sprintf " union % s " ud . ud_name ; let v = new_var " _v " in let c = new_var " _c " in fprintf oc " int camlidl_ml2c_ % s_union_ % s ( value % s , union % s * % s , camlidl_ctx _ctx ) \ n " ud . ud_mod ud . ud_name v ud . ... |
let transl_c_to_ml oc ud = current_function := sprintf " union % s " ud . ud_name ; let discr = new_var " _discr " in let c = new_var " _c " in fprintf oc " value camlidl_c2ml_ % s_union_ % s ( int % s , union % s * % s , camlidl_ctx _ctx ) \ n " ud . ud_mod ud . ud_name d... |
let emit_transl oc ud = transl_ml_to_c oc ud ; transl_c_to_ml oc ud |
module type HashedOrderedType = sig type t val equal : t -> t -> bool val hash : t -> int val compare : t -> t -> int end |
module type S = sig type elt type t val init : elt list -> t val find : elt -> t -> elt val union : elt -> elt -> t -> unit end |
module Make ( X : HashedOrderedType ) = struct type elt = X . t module H = Hashtbl . Make ( X ) type cell = { mutable c : int ; data : elt ; mutable father : cell } type t = cell H . t let init l = let h = H . create 997 in List . iter ( fun x -> let rec cell = { c = 0 ; ... |
let test_check_union context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Union class A : attr : bool = True class B : attr : str = " q " def foo ( y : Union [ A , B ] ) -> None : y . attr = False } | [ " Incompatible attribu... |
let ( ) = " union " >::: [ " check_union " >:: test_check_union ] |> Test . run |
type enum_int = | Enum_int_0 | Enum_int_1 | Enum_int_other of int |
let rec enum_int_of_js : Ojs . t -> enum_int = fun ( x3 : Ojs . t ) t -> let x4 = x3 in match Ojs . int_of_js x4 with | 0 -> Enum_int_0 | 1 -> Enum_int_1 | x5 -> Enum_int_other x5 fun ( x1 : enum_int ) enum_int -> match x1 with | Enum_int_0 -> Ojs . int_to_js 0 | Enum_int_1 -> Ojs . in... |
type enum_float = | Enum_float_0_1 | Enum_float_1_1 | Enum_float_other of float |
let rec enum_float_of_js : Ojs . t -> enum_float = fun ( x8 : Ojs . t ) t -> let x9 = x8 in match Ojs . float_of_js x9 with | 0 . 1 -> Enum_float_0_1 | 1 . 1 -> Enum_float_1_1 | x10 -> Enum_float_other x10 fun ( x6 : enum_float ) enum_float -> match x6 with | Enum_float_0_1 -> Ojs . ... |
type enum_number_1 = | Enum_number_0 | Enum_number_1 | Enum_number_0_1 | Enum_number_1_1 | Enum_number_other of int |
let rec enum_number_1_of_js : Ojs . t -> enum_number_1 = fun ( x13 : Ojs . t ) t -> let x14 = x13 in match Ojs . float_of_js x14 with | 0 . 1 -> Enum_number_0_1 | 1 . 1 -> Enum_number_1_1 | _ -> ( match Ojs . int_of_js x14 with | 0 -> Enum_number_0 | 1 -> Enum_number_1 | x15 -> E... |
type enum_number_2 = | Enum_number_0 | Enum_number_1 | Enum_number_0_1 | Enum_number_1_1 | Enum_number_other of float |
let rec enum_number_2_of_js : Ojs . t -> enum_number_2 = fun ( x18 : Ojs . t ) t -> let x19 = x18 in match Ojs . float_of_js x19 with | 0 . 1 -> Enum_number_0_1 | 1 . 1 -> Enum_number_1_1 | x20 -> ( match Ojs . int_of_js x19 with | 0 -> Enum_number_0 | 1 -> Enum_number_1 | _ -> E... |
type enum_string = | Enum_string_foo | Enum_string_bar | Enum_string_other of string |
let rec enum_string_of_js : Ojs . t -> enum_string = fun ( x23 : Ojs . t ) t -> let x24 = x23 in match Ojs . string_of_js x24 with | " foo " -> Enum_string_foo | " bar " -> Enum_string_bar | x25 -> Enum_string_other x25 fun ( x21 : enum_string ) enum_string -> match x21 with | Enum_st... |
type enum_bool = | Enum_bool_true | Enum_bool_false |
let rec enum_bool_of_js : Ojs . t -> enum_bool = fun ( x27 : Ojs . t ) t -> let x28 = x27 in match Ojs . bool_of_js x28 with | true -> Enum_bool_true | false -> Enum_bool_false fun ( x26 : enum_bool ) enum_bool -> match x26 with | Enum_bool_true -> Ojs . bool_to_js true | Enum_bool_false ->... |
type enum_bool_partial = | Enum_bool_true |
let rec enum_bool_partial_of_js : Ojs . t -> enum_bool_partial = fun ( x30 : Ojs . t ) t -> let x31 = x30 in match Ojs . bool_of_js x31 with | true -> Enum_bool_true | _ -> assert false fun ( x29 : enum_bool_partial ) enum_bool_partial -> match x29 with | Enum_bool_true -> Ojs . bool_to_js t... |
type enum_bool_partial2 = | Enum_bool_true | Enum_bool_other of bool |
let rec enum_bool_partial2_of_js : Ojs . t -> enum_bool_partial2 = fun ( x34 : Ojs . t ) t -> let x35 = x34 in match Ojs . bool_of_js x35 with | true -> Enum_bool_true | x36 -> Enum_bool_other x36 fun ( x32 : enum_bool_partial2 ) enum_bool_partial2 -> match x32 with | Enum_bool_true -> Ojs . b... |
type enum_mixed = | Enum_int_0 | Enum_int_1 | Enum_float_0_1 | Enum_float_1_1 | Enum_number_other of int | Enum_string_foo | Enum_string_bar | Enum_string_other of string | Enum_bool_true | Enum_bool_false |
let rec enum_mixed_of_js : Ojs . t -> enum_mixed = fun ( x40 : Ojs . t ) t -> let x41 = x40 in match Ojs . type_of x41 with | " number " -> ( match Ojs . float_of_js x41 with | 0 . 1 -> Enum_float_0_1 | 1 . 1 -> Enum_float_1_1 | _ -> ( match Ojs . int_of_js x41 with | 0 -> En... |
type enum_mixed_partial_bool = | Enum_int_0 | Enum_int_1 | Enum_float_0_1 | Enum_float_1_1 | Enum_number_other of float | Enum_string_foo | Enum_string_bar | Enum_string_other of string | Enum_bool_true |
let rec enum_mixed_partial_bool_of_js : Ojs . t -> enum_mixed_partial_bool = fun ( x47 : Ojs . t ) t -> let x48 = x47 in match Ojs . type_of x48 with | " number " -> ( match Ojs . float_of_js x48 with | 0 . 1 -> Enum_float_0_1 | 1 . 1 -> Enum_float_1_1 | x49 -> ( match Ojs . int_o... |
type enum_mixed_partial_bool2 = | Enum_int_0 | Enum_int_1 | Enum_float_0_1 | Enum_float_1_1 | Enum_number_other of float | Enum_string_foo | Enum_string_bar | Enum_string_other of string | Enum_bool_true | Enum_bool_other of bool |
let rec enum_mixed_partial_bool2_of_js : Ojs . t -> enum_mixed_partial_bool2 = fun ( x55 : Ojs . t ) t -> let x56 = x55 in match Ojs . type_of x56 with | " number " -> ( match Ojs . float_of_js x56 with | 0 . 1 -> Enum_float_0_1 | 1 . 1 -> Enum_float_1_1 | x57 -> ( match Ojs . int... |
let rec dummy1_of_js : Ojs . t -> dummy1 = fun ( x61 : Ojs . t ) t -> x61 |
let rec dummy2_of_js : Ojs . t -> dummy2 = fun ( x63 : Ojs . t ) t -> x63 |
let rec dummy3_of_js : Ojs . t -> dummy3 = fun ( x65 : Ojs . t ) t -> x65 |
let rec dummy4_of_js : Ojs . t -> dummy4 = fun ( x67 : Ojs . t ) t -> x67 |
let rec dummy5_of_js : Ojs . t -> dummy5 = fun ( x69 : Ojs . t ) t -> x69 |
let rec dummy6_of_js : Ojs . t -> dummy6 = fun ( x71 : Ojs . t ) t -> x71 |
type union_int = | Union_int_0 of dummy1 | Union_int_1 of dummy2 | Unknown of Ojs . t |
let rec union_int_of_js : Ojs . t -> union_int = fun ( x76 : Ojs . t ) t -> let x77 = x76 in match Ojs . type_of ( Ojs . get_prop_ascii x77 " tag ) " with | " number " -> ( match Ojs . int_of_js ( Ojs . get_prop_ascii x77 " tag ) " with | 0 -> Union_int_0 ( dummy1_of_js x... |
type union_float = | Union_float_0_1 of dummy1 | Union_float_1_1 of dummy2 | Unknown of Ojs . t |
let rec union_float_of_js : Ojs . t -> union_float = fun ( x82 : Ojs . t ) t -> let x83 = x82 in match Ojs . type_of ( Ojs . get_prop_ascii x83 " tag ) " with | " number " -> ( match Ojs . float_of_js ( Ojs . get_prop_ascii x83 " tag ) " with | 0 . 1 -> Union_float_0_1 (... |
type union_string = | Union_string_foo of dummy3 | Union_string_bar of dummy4 | Unknown of Ojs . t |
let rec union_string_of_js : Ojs . t -> union_string = fun ( x88 : Ojs . t ) t -> let x89 = x88 in match Ojs . type_of ( Ojs . get_prop_ascii x89 " tag ) " with | " number " -> Unknown x89 | " string " -> ( match Ojs . string_of_js ( Ojs . get_prop_ascii x89 " tag ) " wi... |
type union_bool = | Union_bool_true of dummy5 | Union_bool_false of dummy6 |
let rec union_bool_of_js : Ojs . t -> union_bool = fun ( x93 : Ojs . t ) t -> let x94 = x93 in match Ojs . bool_of_js ( Ojs . get_prop_ascii x94 " tag ) " with | true -> Union_bool_true ( dummy5_of_js x94 ) x94 | false -> Union_bool_false ( dummy6_of_js x94 ) x94 fun ( x90 : union... |
type union_bool_partial = | Union_bool_true of dummy5 |
let rec union_bool_partial_of_js : Ojs . t -> union_bool_partial = fun ( x97 : Ojs . t ) t -> let x98 = x97 in match Ojs . bool_of_js ( Ojs . get_prop_ascii x98 " tag ) " with | true -> Union_bool_true ( dummy5_of_js x98 ) x98 | _ -> assert false fun ( x95 : union_bool_partial ) un... |
type union_bool_partial2 = | Union_bool_true of dummy5 | Unknown of Ojs . t |
let rec union_bool_partial2_of_js : Ojs . t -> union_bool_partial2 = fun ( x102 : Ojs . t ) t -> let x103 = x102 in match Ojs . type_of ( Ojs . get_prop_ascii x103 " tag ) " with | " number " -> Unknown x103 | " string " -> Unknown x103 | " boolean " -> ( match Ojs . bool_of_... |
type union_mixed = | Union_int_0 of dummy1 | Union_int_1 of dummy2 | Union_float_0_1 of dummy1 | Union_float_1_1 of dummy2 | Union_string_foo of dummy3 | Union_string_bar of dummy4 | Union_bool_true of dummy5 | Union_bool_false of dummy6 | Unknown of Ojs . t |
let rec union_mixed_of_js : Ojs . t -> union_mixed = fun ( x114 : Ojs . t ) t -> let x115 = x114 in match Ojs . type_of ( Ojs . get_prop_ascii x115 " tag ) " with | " number " -> ( match Ojs . float_of_js ( Ojs . get_prop_ascii x115 " tag ) " with | 0 . 1 -> Union_float_... |
type union_mixed_partial_bool = | Union_int_0 of dummy1 | Union_int_1 of dummy2 | Union_float_0_1 of dummy1 | Union_float_1_1 of dummy2 | Union_string_foo of dummy3 | Union_string_bar of dummy4 | Union_bool_true of dummy5 | Unknown of Ojs . t |
let rec union_mixed_partial_bool_of_js : Ojs . t -> union_mixed_partial_bool = fun ( x125 : Ojs . t ) t -> let x126 = x125 in match Ojs . type_of ( Ojs . get_prop_ascii x126 " tag ) " with | " number " -> ( match Ojs . float_of_js ( Ojs . get_prop_ascii x126 " tag ) " with | ... |
type uf = { link : int array ; rank : int array ; mutable rep : int -> int ; [ @ ghost ] mutable dst : int -> int ; [ @ ghost ] mutable maxd : int ; [ @ ghost ] } |
let rec find i uf = let p = uf . link . ( i ) in if p = i then i else let rep = find p uf in uf . link . ( i ) <- rep ; rep fun y -> if ( y = x ) [ @ pure ] then v else f y |
let union i j uf = let rep_i = find i uf in let rep_j = find j uf in if not ( rep_i = rep_j ) then if uf . rank . ( rep_i ) > uf . rank . ( rep_j ) then ( uf . link . ( rep_j ) <- rep_i ; uf . rep <- ( fun [ @ pure ] k -> if uf . rep k = uf . rep rep_j then rep_i el... |
let test = " union_find " >::: [ " all " >:: ( fun ( ) -> let t1 = create 13 in assert ( get t1 = 13 ) ; set t1 15 ; assert ( get t1 = 15 ) ; assert ( same_class t1 t1 ) ; let t2 = create 17 in assert ( not ( same_class t1 t2 ) ) ; union t1 t2 ; assert ( sa... |
module MyQuery = [ % graphql { | { dogOrHuman { . . . on Dog { name barkVolume } } } } ] | |
type qt = < dogOrHuman : [ | ` Dog of < name : string ; barkVolume : float > | ` Nonexhaustive ] > |
let my_query = ( module struct type t = qt let pp formatter ( obj : qt ) = Format . fprintf formatter " < dogOrHuman = % a " > ( fun formatter -> function | ` Dog dog -> Format . fprintf formatter " ` Dog [ @<>< name = % a ; barkVolume = % a ] " >@ Format . pp_print_stri... |
let decodes_non_exhaustive_query ( ) = Alcotest . check my_query " result equality " ( MyQuery . parse ( Yojson . Basic . from_string { | { " dogOrHuman " : { " __typename " : " Human " , " name " : " Max " } } } ) ) | ( object method dogOrHuman = ` ... |
let tests = [ " Decodes non - exhaustive query " , ` Quick , decodes_non_exhaustive_query ; ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.