text
stringlengths 0
601k
|
---|
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 -> Enum_int_0 | 1 -> Enum_int_1 | x42 -> Enum_number_other x42 ) x42 ) x42 | " string " -> ( match Ojs . string_of_js x41 with | " foo " -> Enum_string_foo | " bar " -> Enum_string_bar | x43 -> Enum_string_other x43 ) x43 | " boolean " -> ( match Ojs . bool_of_js x41 with | true -> Enum_bool_true | false -> Enum_bool_false ) Enum_bool_false | _ -> assert false fun ( x37 : enum_mixed ) enum_mixed -> match x37 with | Enum_int_0 -> Ojs . int_to_js 0 | Enum_int_1 -> Ojs . int_to_js 1 | Enum_float_0_1 -> Ojs . float_to_js 0 . 1 | Enum_float_1_1 -> Ojs . float_to_js 1 . 1 | Enum_number_other x38 -> Ojs . int_to_js x38 | Enum_string_foo -> Ojs . string_to_js " foo " | Enum_string_bar -> Ojs . string_to_js " bar " | Enum_string_other x39 -> Ojs . string_to_js x39 | Enum_bool_true -> Ojs . bool_to_js true | Enum_bool_false -> Ojs . bool_to_js false |
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_of_js x48 with | 0 -> Enum_int_0 | 1 -> Enum_int_1 | _ -> Enum_number_other x49 ) x49 ) x49 | " string " -> ( match Ojs . string_of_js x48 with | " foo " -> Enum_string_foo | " bar " -> Enum_string_bar | x50 -> Enum_string_other x50 ) x50 | " boolean " -> ( match Ojs . bool_of_js x48 with | true -> Enum_bool_true | _ -> assert false ) false | _ -> assert false fun ( x44 : enum_mixed_partial_bool ) enum_mixed_partial_bool -> match x44 with | Enum_int_0 -> Ojs . int_to_js 0 | Enum_int_1 -> Ojs . int_to_js 1 | Enum_float_0_1 -> Ojs . float_to_js 0 . 1 | Enum_float_1_1 -> Ojs . float_to_js 1 . 1 | Enum_number_other x45 -> Ojs . float_to_js x45 | Enum_string_foo -> Ojs . string_to_js " foo " | Enum_string_bar -> Ojs . string_to_js " bar " | Enum_string_other x46 -> Ojs . string_to_js x46 | Enum_bool_true -> Ojs . bool_to_js true |
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_of_js x56 with | 0 -> Enum_int_0 | 1 -> Enum_int_1 | _ -> Enum_number_other x57 ) x57 ) x57 | " string " -> ( match Ojs . string_of_js x56 with | " foo " -> Enum_string_foo | " bar " -> Enum_string_bar | x58 -> Enum_string_other x58 ) x58 | " boolean " -> ( match Ojs . bool_of_js x56 with | true -> Enum_bool_true | x59 -> Enum_bool_other x59 ) x59 | _ -> assert false fun ( x51 : enum_mixed_partial_bool2 ) enum_mixed_partial_bool2 -> match x51 with | Enum_int_0 -> Ojs . int_to_js 0 | Enum_int_1 -> Ojs . int_to_js 1 | Enum_float_0_1 -> Ojs . float_to_js 0 . 1 | Enum_float_1_1 -> Ojs . float_to_js 1 . 1 | Enum_number_other x52 -> Ojs . float_to_js x52 | Enum_string_foo -> Ojs . string_to_js " foo " | Enum_string_bar -> Ojs . string_to_js " bar " | Enum_string_other x53 -> Ojs . string_to_js x53 | Enum_bool_true -> Ojs . bool_to_js true | Enum_bool_other x54 -> Ojs . bool_to_js x54 |
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 x77 ) x77 | 1 -> Union_int_1 ( dummy2_of_js x77 ) x77 | _ -> Unknown x77 ) x77 | " string " -> Unknown x77 | " boolean " -> Unknown x77 | _ -> Unknown x77 fun ( x72 : union_int ) union_int -> match x72 with | Union_int_0 x73 -> dummy1_to_js x73 | Union_int_1 x74 -> dummy2_to_js x74 | Unknown x75 -> x75 |
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 ( dummy1_of_js x83 ) x83 | 1 . 1 -> Union_float_1_1 ( dummy2_of_js x83 ) x83 | _ -> Unknown x83 ) x83 | " string " -> Unknown x83 | " boolean " -> Unknown x83 | _ -> Unknown x83 fun ( x78 : union_float ) union_float -> match x78 with | Union_float_0_1 x79 -> dummy1_to_js x79 | Union_float_1_1 x80 -> dummy2_to_js x80 | Unknown x81 -> x81 |
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 ) " with | " foo " -> Union_string_foo ( dummy3_of_js x89 ) x89 | " bar " -> Union_string_bar ( dummy4_of_js x89 ) x89 | _ -> Unknown x89 ) x89 | " boolean " -> Unknown x89 | _ -> Unknown x89 fun ( x84 : union_string ) union_string -> match x84 with | Union_string_foo x85 -> dummy3_to_js x85 | Union_string_bar x86 -> dummy4_to_js x86 | Unknown x87 -> x87 |
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_bool ) union_bool -> match x90 with | Union_bool_true x91 -> dummy5_to_js x91 | Union_bool_false x92 -> dummy6_to_js x92 |
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 ) union_bool_partial -> match x95 with | Union_bool_true x96 -> dummy5_to_js x96 |
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_js ( Ojs . get_prop_ascii x103 " tag ) " with | true -> Union_bool_true ( dummy5_of_js x103 ) x103 | _ -> Unknown x103 ) x103 | _ -> Unknown x103 fun ( x99 : union_bool_partial2 ) union_bool_partial2 -> match x99 with | Union_bool_true x100 -> dummy5_to_js x100 | Unknown x101 -> x101 |
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_0_1 ( dummy1_of_js x115 ) x115 | 1 . 1 -> Union_float_1_1 ( dummy2_of_js x115 ) x115 | _ -> ( match Ojs . int_of_js ( Ojs . get_prop_ascii x115 " tag ) " with | 0 -> Union_int_0 ( dummy1_of_js x115 ) x115 | 1 -> Union_int_1 ( dummy2_of_js x115 ) x115 | _ -> Unknown x115 ) x115 ) x115 | " string " -> ( match Ojs . string_of_js ( Ojs . get_prop_ascii x115 " tag ) " with | " foo " -> Union_string_foo ( dummy3_of_js x115 ) x115 | " bar " -> Union_string_bar ( dummy4_of_js x115 ) x115 | _ -> Unknown x115 ) x115 | " boolean " -> ( match Ojs . bool_of_js ( Ojs . get_prop_ascii x115 " tag ) " with | true -> Union_bool_true ( dummy5_of_js x115 ) x115 | false -> Union_bool_false ( dummy6_of_js x115 ) x115 ) x115 | _ -> Unknown x115 fun ( x104 : union_mixed ) union_mixed -> match x104 with | Union_int_0 x105 -> dummy1_to_js x105 | Union_int_1 x106 -> dummy2_to_js x106 | Union_float_0_1 x107 -> dummy1_to_js x107 | Union_float_1_1 x108 -> dummy2_to_js x108 | Union_string_foo x109 -> dummy3_to_js x109 | Union_string_bar x110 -> dummy4_to_js x110 | Union_bool_true x111 -> dummy5_to_js x111 | Union_bool_false x112 -> dummy6_to_js x112 | Unknown x113 -> x113 |
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 | 0 . 1 -> Union_float_0_1 ( dummy1_of_js x126 ) x126 | 1 . 1 -> Union_float_1_1 ( dummy2_of_js x126 ) x126 | _ -> ( match Ojs . int_of_js ( Ojs . get_prop_ascii x126 " tag ) " with | 0 -> Union_int_0 ( dummy1_of_js x126 ) x126 | 1 -> Union_int_1 ( dummy2_of_js x126 ) x126 | _ -> Unknown x126 ) x126 ) x126 | " string " -> ( match Ojs . string_of_js ( Ojs . get_prop_ascii x126 " tag ) " with | " foo " -> Union_string_foo ( dummy3_of_js x126 ) x126 | " bar " -> Union_string_bar ( dummy4_of_js x126 ) x126 | _ -> Unknown x126 ) x126 | " boolean " -> ( match Ojs . bool_of_js ( Ojs . get_prop_ascii x126 " tag ) " with | true -> Union_bool_true ( dummy5_of_js x126 ) x126 | _ -> Unknown x126 ) x126 | _ -> Unknown x126 fun ( x116 : union_mixed_partial_bool ) union_mixed_partial_bool -> match x116 with | Union_int_0 x117 -> dummy1_to_js x117 | Union_int_1 x118 -> dummy2_to_js x118 | Union_float_0_1 x119 -> dummy1_to_js x119 | Union_float_1_1 x120 -> dummy2_to_js x120 | Union_string_foo x121 -> dummy3_to_js x121 | Union_string_bar x122 -> dummy4_to_js x122 | Union_bool_true x123 -> dummy5_to_js x123 | Unknown x124 -> x124 |
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 else uf . rep k ) ; uf . maxd <- uf . maxd + 1 ; uf . dst <- set uf . dst rep_i ( 1 + max ( uf . dst rep_i ) ( uf . dst rep_j ) ) ) else ( uf . link . ( rep_i ) <- rep_j ; uf . rep <- ( fun [ @ pure ] k -> if uf . rep k = uf . rep rep_i then rep_j else uf . rep k ) ; uf . maxd <- uf . maxd + 1 ; uf . dst <- set uf . dst rep_j ( 1 + max ( uf . dst rep_i ) ( uf . dst rep_j ) ) ; if uf . rank . ( rep_i ) = uf . rank . ( rep_j ) then uf . rank . ( rep_i ) <- uf . rank . ( rep_i ) + 1 ) |
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 ( same_class t1 t1 ) ; assert ( same_class t1 t2 ) ; assert ( same_class t2 t2 ) ; assert ( get t1 = get t2 ) ; assert ( get t1 = 15 || get t1 = 17 ) ; let t3 = create 19 in union t1 t3 ; let t4 = create 21 in assert ( not ( same_class t3 t4 ) ) ; union t1 t4 ; assert ( same_class t3 t4 ) ; ) ; " zzz " >:: ( fun ( ) -> let u1 = create ( ) in let u2 = create ( ) in let u3 = create ( ) in let u4 = create ( ) in union u1 u2 ; union u3 u4 ; union u2 u4 ; assert ( same_class u1 u3 ) ; ) ; ] ; ; |
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_string dog # name Format . pp_print_float dog # barkVolume | ` Nonexhaustive -> Format . fprintf formatter " ` Nonexhaustive " ) obj # dogOrHuman let equal ( a : qt ) ( b : qt ) = match a # dogOrHuman , b # dogOrHuman with | ( ` Dog a ) , ( ` Dog b ) -> a # name = b # name && a # barkVolume = b # barkVolume | ` Nonexhaustive , ` Nonexhaustive -> true | _ -> false end : Alcotest . TESTABLE with type t = qt ) |
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 = ` Nonexhaustive end ) |
let tests = [ " Decodes non - exhaustive query " , ` Quick , decodes_non_exhaustive_query ; ] |
module Make ( ArtLib : ArtLib . S ) ( Name : Name . S ) ( Elt : Data . S ) ( St : SpreadTree . S with type name = Name . t and type elt = Elt . t ) = struct module List = St . List module Set = Trie . Set . Make ( Name ) ( ArtLib ) ( Elt ) let list_unique : ( Elt . t * Elt . t ) -> List . t -> List . t = fun ( zero , one ) -> let loop = List . Art . mk_mfn ( Name . of_string " Unique # list_unique " ) ( module Types . Tuple3 ( Name ) ( List ) ( Set ) ) ( fun loop ( nm , l , s ) -> match l with | ` Nil -> ` Nil | ` Cons ( i , l ' ) -> ( let nm1 , nm2 = Name . fork nm in let i ' , s ' = if Set . mem s i then one , s else zero , Set . add nm1 s i in ` Cons ( i ' , loop . List . Art . mfn_data ( nm2 , l ' , s ' ) ) ) | ` Art a -> loop . List . Art . mfn_data ( nm , List . Art . force a , s ) | ` Name ( nm , l ' ) -> let nm1 , nm = Name . fork nm in let nm2 , nm3 = Name . fork nm in ` Name ( nm1 , ` Art ( loop . List . Art . mfn_nart nm2 ( nm3 , l ' , s ) ) ) ) in ( fun l -> loop . List . Art . mfn_data ( Name . of_string " Unique . list_unique # root_nm " , l , Set . empty ~ min_depth ? art_ifreq : None ) ) end |
let list_unique : List . Data . t -> List . Data . t = let loop = List . Art . mk_mfn ( Key . of_string " Unique # list_unique " ) ( module AdaptonTypes . Tuple3 ( Key ) ( List . Data ) ( Set ) ) ( fun loop ( nm , l , s ) -> match l with | ` Nil -> ` Nil | ` Cons ( i , l ' ) -> let nm ' , nm ' ' = Key . fork nm in let i ' , s ' = if Set . mem s i then 1 , s else 0 , Set . nadd nm ' s i in ` Cons ( i ' , loop . mfn_data ( nm ' ' , l ' , s ' ) ) | ` Art a -> loop . mfn_data ( nm , List . Art . force a , s ) | ` Name ( nm , l ' ) -> let nm ' , nm ' ' = Key . fork nm in ` Name ( nm ' , ` Art ( loop . mfn_nart nm ' ' ( nm ' ' , l ' , s ) ) ) ) in ( fun l -> loop . mfn_data ( Key . of_string " Unique . list_unique # root_nm " , l , Set . empty ~ min_depth ) ) |
let lthunk : List . Data . t -> List . Art . t = let ident = List . Art . mk_mfn ( Key . of_string " Unique # lthunk " ) ( module List . Data ) ( fun _ l -> l ) in ident . mfn_art |
let _ = let name l = ` Name ( Key . nondet ( ) , ` Art ( lthunk l ) ) in let al_of_l ( l : int list ) : List . Data . t = OList . fold_right ( fun n a -> name ( ` Cons ( n , a ) ) ) l ` Nil in let rec l_of_al : List . Data . t -> int list = function | ` Nil -> [ ] | ` Cons ( i , l ) -> i ( :: l_of_al l ) | ` Art a -> l_of_al ( List . Art . force a ) | ` Name ( _ , l ) -> l_of_al l in let l0 : int list = [ ] and a0 : int list = [ ] and l1 = [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] and a1 = [ 0 ; 0 ; 0 ; 0 ; 0 ; 0 ; 0 ; 0 ; 0 ; 0 ] and l2 = [ 0 ; 1 ; 0 ; 2 ; 0 ; 3 ; 0 ; 4 ; 0 ; 5 ] and a2 = [ 0 ; 0 ; 1 ; 0 ; 1 ; 0 ; 1 ; 0 ; 1 ; 0 ] in let test l a = let al = al_of_l l in let al ' = list_unique al in if l_of_al al ' = a then print_endline " test passed " ! else print_endline " test failed . " in test l0 a0 ; test l1 a1 ; test l2 a2 ) * |
module type Id = Id |
let rec race_free_create_loop cell make = let x = ! cell in let new_x = make x in if phys_equal ! cell x then ( cell := new_x ; x ) else race_free_create_loop cell make ; ; |
module Int ( ) = struct include Int let current = ref zero let create ( ) = race_free_create_loop current succ end |
module Int63 ( ) = struct include Int63 let current = ref zero let create ( ) = race_free_create_loop current succ end |
let test_reserved_identifiers ( ) = let u = U . init ~ reserved_identifiers [ " : y " ] ~ reserved_prefixes [ ] : ~ safe_prefix " : x_ " in Alcotest . ( check ( option string ) ) " equal " None ( U . translate_only u " a " ) ; Alcotest . ( check string ) " equal " " a " ( U . translate u " a " ) ; Alcotest . ( check string ) " equal " " a " ( U . translate u " a " ) ; Alcotest . ( check ( option string ) ) " equal " ( Some " a " ) ( U . translate_only u " a " ) ; Alcotest . ( check string ) " equal " " y_ " ( U . translate u " y_ " ) ; Alcotest . ( check string ) " equal " " y2 " ( U . translate u " y " ) ; let u = U . init ~ reserved_identifiers [ " : y " ] ~ reserved_prefixes [ " : y_ " ] ~ safe_prefix " : x_ " in Alcotest . ( check string ) " equal " " x_y_ " ( U . translate u " y " ) |
let test_reserved_prefixes ( ) = ( try U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " " ] : ~ safe_prefix " : x_ " |> ignore ; assert false with _ -> ( ) ) ; ( try U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " : x " ] ~ safe_prefix " : x_ " |> ignore ; assert false with _ -> ( ) ) ; let u = U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " : y_ " ] ~ safe_prefix " : x_ " in Alcotest . ( check string ) " equal " " a " ( U . translate u " a " ) ; Alcotest . ( check string ) " equal " " x_y_a " ( U . translate u " y_a " ) ; Alcotest . ( check string ) " equal " " x_y_a " ( U . translate u " y_a " ) ; Alcotest . ( check string ) " equal " " x_y_a_ " ( U . translate u " x_y_a_ " ) ; Alcotest . ( check string ) " equal " " x_y_a2 " ( U . translate u " x_y_a " ) ; Alcotest . ( check ( option string ) ) " equal " ( Some " x_y_a " ) ( U . reverse_translate u " x_y_a2 " ) |
let test_identifier_creation ( ) = let u = U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " : y_ " ] ~ safe_prefix " : x_ " in Alcotest . ( check string ) " equal " " y " ( U . translate u " y " ) ; Alcotest . ( check string ) " equal " " y_ " ( U . create u " y " ) ; Alcotest . ( check string ) " equal " " x_y_ " ( U . translate u " y_ " ) ; Alcotest . ( check string ) " equal " " y2 " ( U . create u " y " ) ; Alcotest . ( check string ) " equal " " y2 " ( U . translate u " y2 " ) |
let test : unit Alcotest . test = " Unique_name " , [ " reserved identifiers " , ` Quick , test_reserved_identifiers ; " reserved prefixes " , ` Quick , test_reserved_prefixes ; " identifier creation " , ` Quick , test_identifier_creation ; ] |
module M = struct type t = B let f : t -> t = fun B -> x end ; ; [ %% expect { | |
type t = A ^ t / 1 Line 4 , characters 2 - 12 : Definition of type t / 1 Line 1 , characters 0 - 10 : Definition of type t / 2 } ] | |
module M = struct type t = B end |
module N = struct module M = struct type t = C end let f : M . t -> M . t = fun M . C -> y end ; ; [ %% expect { | |
module M : sig type t = B end ^ M / 1 . t Lines 4 - 6 , characters 2 - 5 : Definition of module M / 1 Line 1 , characters 0 - 32 : Definition of module M / 2 } ] | |
let f : t -> t = fun D -> x ; ; [ %% expect { | |
type t = D ^ t / 1 Line 1 , characters 0 - 10 : Definition of type t / 1 Line 1 , characters 0 - 10 : Definition of type t / 2 } ] | |
type ttt = A of ttt | B of uuu [ %% expect { | |
type ttt = A of ttt | B of uuu } ] | |
type nonrec ttt = X of ttt |
let x : ttt = let rec y = A y in y ; ; [ %% expect { | |
type nonrec ttt = X of ttt ^ ttt / 1 Line 1 , characters 0 - 26 : Definition of type ttt / 1 Line 2 , characters 0 - 30 : Definition of type ttt / 2 } ] | |
let safe_ascii c = ( c >= ' a ' && c <= ' z ' ) || ( c >= ' A ' && c <= ' Z ' ) || c = ' _ ' || ( c >= ' 0 ' && c <= ' 9 ' ) |
let safe_ascii_only s = CCString . filter_map ( fun c -> if safe_ascii c then Some c else None ) s |
let safe_ascii_only_ml s = CCString . filter_map ( fun c -> if safe_ascii c || c = ' ' ' \ then Some c else None ) s |
let unsuffixed_file_name ( ) = let loc = ! Ast_helper . default_loc in let name = Filename . basename loc . Lo . loc_start . Le . pos_fname in match CCString . split_on_char ' . ' name with | [ ] -> " " | s :: _ -> safe_ascii_only s |
let make_uniq_cnt htl s = let i = match Hashtbl . find htl s with exception Not_found -> 0 | n -> n in Hashtbl . replace htl s ( succ i ) ; i |
let htl_c = Hashtbl . create 128 |
let safe_cname = let cnt = make_uniq_cnt htl_c in fun ~ prefix -> let loc = ! Ast_helper . default_loc in let name = unsuffixed_file_name ( ) in let s = safe_ascii_only prefix in let cutmax s maxlen = let len = String . length s in if len > maxlen then String . sub s 0 maxlen else s in let s = cutmax s 20 in let name = cutmax name 40 in let line = loc . Lo . loc_start . Le . pos_lnum in let cnum = loc . Lo . loc_start . Le . pos_cnum in let res = Printf . sprintf " % s_ % x_ % x_ % s " name line cnum s in match cnt res with | 0 -> " ppxc_ " ^ res | i -> Printf . sprintf " ppxc % x_ % s " i res |
let htl_ml = Hashtbl . create 128 |
let safe_mlname = let cnt = make_uniq_cnt htl_ml in fun ( ? capitalize = false ) ? prefix ( ) -> let s , p = match prefix with | None -> ( " " , " " ) | Some s -> ( safe_ascii_only_ml s , " _ " ) in let loc = ! Ast_helper . default_loc in let line = loc . Lo . loc_start . Le . pos_lnum in let pre = if capitalize then Myconst . private_prefix_capitalized else Myconst . private_prefix in let f = pre . [ 0 ] in let pre = String . sub pre 1 ( String . length pre - 1 ) in let res = Printf . sprintf " % c % s % s % sline % d " f pre s p line in match cnt res with 0 -> res | i -> Printf . sprintf " % s_ % d " res i |
type merlin_state = { l_c : ( string * int ) list ; l_ml : ( string * int ) list ; } |
let merlin_save ( ) : merlin_state = { l_c = CCHashtbl . Poly . to_list htl_c ; l_ml = CCHashtbl . Poly . to_list htl_ml } |
let merlin_restore { l_c ; l_ml } = let f htl l = Hashtbl . clear htl ; List . iter ( fun ( a , b ) -> Hashtbl . replace htl a b ) l in f htl_c l_c ; f htl_ml l_ml |
let htl_ctypes = Hashtbl . create 64 |
type t = { mod_path : string list ; uniq_name : string ; short_name : string ; sref : string ; } |
type make_result = { id : t ; topmod_vb : structure_item ; topmod_ref : structure_item ; main_ref : expression ; } |
let attr ~ attr ~ cont = let loc = ! Ast_helper . default_loc in let x = U . mk_loc attr in let pl = PStr [ [ % stri [ % e U . str_expr cont ] ] ] in [ Ast_helper . Attr . mk x pl ] |
let vb ? constr ~ attrs n expr = let p = match constr with None -> U . mk_pat n | Some t -> U . mk_pat_pconstr t n in Str . value Nonrecursive [ Vb . mk ~ attrs p expr ] |
let make ? constr ? main_ref_attrs ~ retype mod_path short_name expr = let uniq_name = U . safe_mlname ~ prefix : short_name ( ) in let sref = String . concat " . " ( mod_path @ [ short_name ] ) in Hashtbl . add htl_ctypes sref ( ) ; let id = { mod_path ; uniq_name ; short_name ; sref } in let attrs = attr ~ cont : sref ~ attr : a_inmod_ref in let attrs = if Ocaml_config . version ( ) < ( 4 , 6 , 0 ) then attrs else U . ocaml_warning " - 32 " :: attrs in let topmod_ref = vb ~ attrs short_name ( U . mk_ident_l [ uniq_name ] ) in let cont = sref ^ " " | ^ sref in let attrs1 = attr ~ cont ~ attr : a_reference_string in let attrs2 = match main_ref_attrs with None -> attrs1 | Some x -> x @ attrs1 in let n = mod_path @ [ uniq_name ] in let main_ref = if retype = false || Ocaml_config . use_open_struct ( ) = false then Exp . ident ~ attrs : attrs2 ( U . mk_lid_l n ) else let e = Exp . ident ~ attrs : attrs1 ( U . mk_lid_l n ) in U . alias_type ? attrs : main_ref_attrs e in let attrs = attr ~ cont : sref ~ attr : a_orig_name in let topmod_vb = vb ? constr ~ attrs uniq_name expr in { id ; topmod_vb ; topmod_ref ; main_ref } |
let get_remove_string_exn name attr = let res = ref None in let attribs = List . filter attr ~ f ( : fun x -> if x . attr_name . txt <> name then true else match x . attr_payload with | PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( s , _ , _ ) ) ; _ ; } , _ ) ; _ ; } ; ] -> res := Some s ; false | _ -> failwith " surprising content in attribute " ) in match ! res with | None -> failwith " invalid parsetree generated " | Some s -> ( s , attribs ) |
let is_uniq_ctype orig = match Hashtbl . find_all htl_ctypes orig with | [ _ ] -> true | [ ] -> failwith " invalid parsetree generated " | _ -> false |
let get_final_name t = if is_uniq_ctype t . sref then t . short_name else t . uniq_name |
let replace_expr = function | { pexp_desc = Pexp_ident _ as orig ; pexp_attributes = _ :: _ as attribs ; _ } as expr when List . exists attribs ~ f ( : fun x -> x . attr_name . txt = a_reference_string ) -> let s , pexp_attributes = get_remove_string_exn a_reference_string attribs in let id_ref , single_ref = CCString . Split . left_exn ~ by " " :| s in let pexp_desc = match is_uniq_ctype id_ref with | false -> orig | true -> Pexp_ident ( U . mk_lid single_ref ) in { expr with pexp_desc ; pexp_attributes } | expr -> expr |
let replace_stri = function | { pstr_desc = Pstr_value ( Nonrecursive , [ ( { pvb_attributes = _ :: _ as attribs ; _ } as a ) ] ) ; _ ; } as stri -> if List . exists attribs ~ f ( : fun x -> x . attr_name . txt = a_orig_name ) then let s , pvb_attributes = get_remove_string_exn a_orig_name attribs in let pvb_pat = match is_uniq_ctype s with | false -> a . pvb_pat | true -> ( let n = CCString . Split . right_exn ~ by " . " : s |> snd |> U . mk_pat in match a . pvb_pat . ppat_desc with | Ppat_constraint ( _ , c ) -> Pat . constraint_ n c | _ -> n ) in let a = { a with pvb_attributes ; pvb_pat } in { stri with pstr_desc = Pstr_value ( Nonrecursive , [ a ] ) } else if List . exists attribs ~ f ( : fun x -> x . attr_name . txt = a_inmod_ref ) then let s , pvb_attributes = get_remove_string_exn a_inmod_ref attribs in if is_uniq_ctype s then U . empty_stri ( ) else let a = { a with pvb_attributes } in let stri = { stri with pstr_desc = Pstr_value ( Nonrecursive , [ a ] ) } in U . no_warn_unused_pre406 stri else stri | stri -> stri |
let clear ( ) = Hashtbl . clear htl_ctypes |
type merlin_state = string list |
let merlin_save ( ) = CCHashtbl . Poly . to_list htl_ctypes |> List . split |> fst |
let merlin_restore l = clear ( ) ; List . iter l ~ f ( : fun x -> Hashtbl . add htl_ctypes x ( ) ) |
let desc = [ ` Path " lablgtk - 1 . 00 / config . make " ; ` Path " lablgtk - 1 . 00 / lablgtktop_t " ; ` Path " lablgtk - 1 . 00 / lablgtktop " ; ` Path " lablgtk - 1 . 00 / lablgtkrun " ; ` Path " lablgtk - 1 . 00 / lablgtk " ; ` Path " unison3 / src / unison " ; ` Name " core " ; ` Path " lipe / caisse / val_parse . h " ; ` Path " lipe / caisse / val_parse . c " ; ` Path " lipe / caisse / val_lex . c " ; ` Path " lipe / caisse / caisse " ; ` Path " lipe / runtime " ; ` Path " lipe / demo " ; ` Path " unison2 / doc / unison - manual . ps " ; ` Path " unison / doc / unison - mal . ps " ; ` Name " . * ppi " ; ` Path " unison2 / src / unison " ; ` Path " Xduce / xduce / pref . ml " ; ` Path " Xduce / xduce / xduce { , . opt } " ; ` Path " unison / src / TAGS " ; ` Path " unison / src / unison " ; ` Name " . * old " ; ` Name " " ; #*# ` Name " . * cm { i , o , x , a , xa } " ; ` Name " . * vo " ; ` Name " { , . *~ aux , . bbl , . blg , . log , . toc , . o , . a } " ; ` Name " gmon . out " ; ` Name " ocamlprof . dump " ; ` Name " CVS " ; ` Name " . . * prcs_aux " ; ` Path " icfp2000 / tools / src2tex " ; ` Path " icfp2000 / temp . dvi " ; ` Path " icfp2000 / main . dvi " ; ` Path " icfp2000 / whole . dvi " ; ` Path " icfp2000 / regsub . ps " ; ` Path " Views / main . dvi " ; ` Path " lipe / perso / caisse " ; ` Name " obsolete " ; ` Path " misc / fingerprint / cksum / cksum " ; ` Path " misc / relay / relay " ; ` Path " Xduce / xduce . current / xduce . opt " ; ` Path " Xduce / xduce . current / pref . ml " ; ` Path " Xduce / xduce . new / pref . ml " ; ` Path " Xduce / xduce . new / xduce . opt " ; ` Path " profiler / profiler " ; ` Path " ocaml / boot / Saved " ; ` Path " ocaml / byterun / ocamlrun " ; ` Path " ocaml / config / Makefile " ; ` Path " ocaml / config / m . h " ; ` Path " ocaml / config / s . h " ; ` Path " ocaml / expunge " ; ` Path " ocaml / asmcomp / arch . ml " ; ` Path " ocaml / asmcomp / emit . ml " ; ` Path " ocaml / asmcomp / proc . ml " ; ` Path " ocaml / asmcomp / reload . ml " ; ` Path " ocaml / asmcomp / scheduling . ml " ; ` Path " ocaml / asmcomp / selection . ml " ; ` Path " ocaml / debugger / ocamldebug " ; ` Path " ocaml / lex / ocamllex " ; ` Path " ocaml / ocaml " ; ` Path " ocaml / ocamlc " ; ` Path " ocaml / ocamlopt " ; ` Path " ocaml / otherlibs / dynlink / extract_crc " ; ` Path " ocaml / otherlibs / labltk / browser / ocamlbrowser " ; ` Path " ocaml / otherlibs / labltk / compiler / tkcompiler " ; ` Path " ocaml / otherlibs / str / regex - 0 . 12 / config . status " ; ` Path " ocaml / stdlib / camlheader " ; ` Path " ocaml / tools / cvt_emit " ; ` Path " ocaml / boot / camlheader " ; ` Path " ocaml / boot / ocamlrun " ; ` Path " ocaml / boot / ocamlyacc " ; ` Path " ocaml / otherlibs / labltk / lib . / depend " ; ` Path " ocaml / otherlibs / labltk / lib / labltk " ; ` Path " ocaml / otherlibs / labltk / lib / labltktop " ; ` Path " ocaml / otherlibs / labltk / lib / tk . ml " ; ` Path " ocaml / tools / ocamlcp " ; ` Path " ocaml / tools / ocamldep " ; ` Path " ocaml / tools / ocamlmktop " ; ` Path " ocaml / tools / ocamlprof " ; ` Path " ocaml / utils / config . ml " ; ` Path " ocaml / yacc / ocamlyacc " ; ` Path " Xduce / interleave / tools / src2tex " ; ` Path " xml / parser " ; ` Path " ocaml / ocamlopt . opt " ; ` Path " ocaml / boot / ocamlc " ; ` Path " ocaml / boot / ocamllex " ; ` Path " ocaml / ocamlc . opt " ; ` Path " specs / tools / src2f " ; ` Path " specs / tools / src2tex " ] |
let paths = [ " These " ; " Xduce " ; " unison " ; " unison2 " ; " unison3 " ; " tinkertype " ; " lipe " ; " icfp2000 " ; " Views " ; " sync " ; " misc " ; " lablgtk - 1 . 00 " ; " mydb " ; " yacc " ; " db - papers " ; " submissions " ; " xml " ; " profiler " ; " specs " ; " ocaml " ; " rx " ] |
let rec children p = let rec loop ch dir = try let file = Unix . readdir dir in let ch ' = if file = " . " || file = " . . " then ch else file :: ch in loop ch ' dir with End_of_file -> ch in let dir = Unix . opendir p in let result = loop [ ] dir in Unix . closedir dir ; result |
let is_dir p = try ( Unix . lstat p ) . Unix . st_kind = Unix . S_DIR with Unix . Unix_error _ -> false |
let count = ref 0 |
let hit = ref 0 |
let rec visit rx p = try ignore ( Re . exec ~ group : false rx p ) ; with Not_found -> let fp = prefix ^ p in if is_dir fp then List . iter ( fun n -> visit rx ( p ^ " " / ^ n ) ) ( children fp ) |
let _ = let rx = Re . seq [ Re . bos ; Re . alt ( List . map ( fun p -> match p with ` Path s -> Re . Glob . globx s | ` Name s -> Re . seq [ Re . no_group ( Re_posix . re " ( . ) " ) ; */? Re . Glob . globx s ] ) desc ) ; Re . eos ] in let rx = Re . compile rx in List . iter ( fun p -> visit rx p ) paths done |
let desc = [ ` Path " lablgtk - 1 . 00 / config . make " ; ` Path " lablgtk - 1 . 00 / lablgtktop_t " ; ` Path " lablgtk - 1 . 00 / lablgtktop " ; ` Path " lablgtk - 1 . 00 / lablgtkrun " ; ` Path " lablgtk - 1 . 00 / lablgtk " ; ` Path " unison3 / src / unison " ; ` Name " core " ; ` Path " lipe / caisse / val_parse . h " ; ` Path " lipe / caisse / val_parse . c " ; ` Path " lipe / caisse / val_lex . c " ; ` Path " lipe / caisse / caisse " ; ` Path " lipe / runtime " ; ` Path " lipe / demo " ; ` Path " unison2 / doc / unison - manual . ps " ; ` Path " unison / doc / unison - mal . ps " ; ` Name " . * ppi " ; ` Path " unison2 / src / unison " ; ` Path " Xduce / xduce / pref . ml " ; ` Path " Xduce / xduce / xduce { , . opt } " ; ` Path " unison / src / TAGS " ; ` Path " unison / src / unison " ; ` Name " . * old " ; ` Name " " ; #*# ` Name " . * cm { i , o , x , a , xa } " ; ` Name " . * vo " ; ` Name " { , . *~ aux , . bbl , . blg , . log , . toc , . o , . a } " ; ` Name " gmon . out " ; ` Name " ocamlprof . dump " ; ` Name " CVS " ; ` Name " . . * prcs_aux " ; ` Path " icfp2000 / tools / src2tex " ; ` Path " icfp2000 / temp . dvi " ; ` Path " icfp2000 / main . dvi " ; ` Path " icfp2000 / whole . dvi " ; ` Path " icfp2000 / regsub . ps " ; ` Path " Views / main . dvi " ; ` Path " lipe / perso / caisse " ; ` Name " obsolete " ; ` Path " misc / fingerprint / cksum / cksum " ; ` Path " misc / relay / relay " ; ` Path " Xduce / xduce . current / xduce . opt " ; ` Path " Xduce / xduce . current / pref . ml " ; ` Path " Xduce / xduce . new / pref . ml " ; ` Path " Xduce / xduce . new / xduce . opt " ; ` Path " profiler / profiler " ; ` Path " ocaml / boot / Saved " ; ` Path " ocaml / byterun / ocamlrun " ; ` Path " ocaml / config / Makefile " ; ` Path " ocaml / config / m . h " ; ` Path " ocaml / config / s . h " ; ` Path " ocaml / expunge " ; ` Path " ocaml / asmcomp / arch . ml " ; ` Path " ocaml / asmcomp / emit . ml " ; ` Path " ocaml / asmcomp / proc . ml " ; ` Path " ocaml / asmcomp / reload . ml " ; ` Path " ocaml / asmcomp / scheduling . ml " ; ` Path " ocaml / asmcomp / selection . ml " ; ` Path " ocaml / debugger / ocamldebug " ; ` Path " ocaml / lex / ocamllex " ; ` Path " ocaml / ocaml " ; ` Path " ocaml / ocamlc " ; ` Path " ocaml / ocamlopt " ; ` Path " ocaml / otherlibs / dynlink / extract_crc " ; ` Path " ocaml / otherlibs / labltk / browser / ocamlbrowser " ; ` Path " ocaml / otherlibs / labltk / compiler / tkcompiler " ; ` Path " ocaml / otherlibs / str / regex - 0 . 12 / config . status " ; ` Path " ocaml / stdlib / camlheader " ; ` Path " ocaml / tools / cvt_emit " ; ` Path " ocaml / boot / camlheader " ; ` Path " ocaml / boot / ocamlrun " ; ` Path " ocaml / boot / ocamlyacc " ; ` Path " ocaml / otherlibs / labltk / lib . / depend " ; ` Path " ocaml / otherlibs / labltk / lib / labltk " ; ` Path " ocaml / otherlibs / labltk / lib / labltktop " ; ` Path " ocaml / otherlibs / labltk / lib / tk . ml " ; ` Path " ocaml / tools / ocamlcp " ; ` Path " ocaml / tools / ocamldep " ; ` Path " ocaml / tools / ocamlmktop " ; ` Path " ocaml / tools / ocamlprof " ; ` Path " ocaml / utils / config . ml " ; ` Path " ocaml / yacc / ocamlyacc " ; ` Path " Xduce / interleave / tools / src2tex " ; ` Path " xml / parser " ; ` Path " ocaml / ocamlopt . opt " ; ` Path " ocaml / boot / ocamlc " ; ` Path " ocaml / boot / ocamllex " ; ` Path " ocaml / ocamlc . opt " ; ` Path " specs / tools / src2f " ; ` Path " specs / tools / src2tex " ] |
let paths = [ " These " ; " Xduce " ; " unison " ; " unison2 " ; " unison3 " ; " tinkertype " ; " lipe " ; " icfp2000 " ; " Views " ; " sync " ; " misc " ; " lablgtk - 1 . 00 " ; " mydb " ; " yacc " ; " db - papers " ; " submissions " ; " xml " ; " profiler " ; " specs " ; " ocaml " ; " rx " ] |
let rec children p = let rec loop ch dir = try let file = Unix . readdir dir in let ch ' = if file = " . " || file = " . . " then ch else file :: ch in loop ch ' dir with End_of_file -> ch in let dir = Unix . opendir p in let result = loop [ ] dir in Unix . closedir dir ; result |
let is_dir p = try ( Unix . lstat p ) . Unix . st_kind = Unix . S_DIR with Unix . Unix_error _ -> false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.