text stringlengths 0 601k |
|---|
module type S = sig type data type t val create : int -> t val clear : t -> unit val merge : t -> data -> data val add : t -> data -> unit val remove : t -> data -> unit val find : t -> data -> data val find_opt : t -> data -> data option val find_all : t -> data -> data list val mem : t -> data -> bool val iter : ( da... |
module Make ( H : Hashtbl . HashedType ) : ( S with type data = H . t ) = struct type ' a weak_t = ' a t let weak_create = create let emptybucket = weak_create 0 type data = H . t type t = { mutable table : data weak_t array ; mutable hashes : int array array ; mutable limit : int ; mutable oversize : int ; mutable rov... |
type ' a t = { mutable size : int ; mutable array : ' a Weak . t ; } |
let create n = { size = 0 ; array = Weak . create ( max 1 n ) } |
let clear xs = let threshold = Weak . length xs . array * 2 / 3 in if xs . size < threshold then Obj . truncate ( Obj . repr xs . array ) ( 1 + threshold ) ; xs . size <- 0 |
let exists xs x = let rec loop i = if i < xs . size then match Weak . get xs . array i with | Some y when x == y -> true | _ -> loop ( i + 1 ) else false in loop 0 |
let add xs x = if not ( exists xs x ) then ( if Weak . length xs . array = xs . size then begin let array = Weak . create ( xs . size * 3 / 2 + 1 ) in let j = ref 0 in for i = 0 to xs . size - 1 do match Weak . get xs . array i with | Some _ as x ' opt -> Weak . set array ! j x ' opt ; incr j | None -> ( ) done ; xs . ... |
let fold fn xs acc = let acc = ref acc in let j = ref 0 in for i = 0 to xs . size - 1 do match Weak . get xs . array i with | Some x as x ' opt -> acc := fn x ! acc ; if ! j < i then Weak . set xs . array ! j x ' opt ; incr j | None -> ( ) done ; xs . size <- ! j ; ! acc |
type typed_dictionary_mismatch = | MissingRequiredField of { field_name : Identifier . t ; class_name : Identifier . t ; } | FieldTypeMismatch of { field_name : Identifier . t ; expected_type : Type . t ; actual_type : Type . t ; class_name : Identifier . t ; } | UndefinedField of { field_name : Identifier . t ; class_... |
type weakened_type = { resolved : Type . t ; typed_dictionary_errors : typed_dictionary_mismatch Node . t list ; } |
let typed_dictionary_errors { typed_dictionary_errors ; _ } = typed_dictionary_errors |
let resolved_type { resolved ; _ } = resolved |
let make_weakened_type ( ? typed_dictionary_errors = [ ] ) resolved = { resolved ; typed_dictionary_errors } |
let combine_weakened_types weakened_types = { resolved = Type . union ( List . map weakened_types ~ f : resolved_type ) ; typed_dictionary_errors = List . concat_map weakened_types ~ f : typed_dictionary_errors ; } |
let undefined_field_mismatches ~ location ~ expected_typed_dictionary : { Type . Record . TypedDictionary . fields = expected_fields ; name = class_name } ~ resolved_typed_dictionary { : Type . Record . TypedDictionary . fields = resolved_fields ; _ } = let make_undefined_field_mismatch { Type . Record . TypedDictionar... |
let distribute_union_over_parametric ~ parametric_name ~ number_of_parameters annotation = match annotation with | Type . Union parameters -> let extract_matching_parameters = function | Type . Parametric { name ; parameters } when Identifier . equal name parametric_name && List . length parameters = number_of_paramete... |
let rec weaken_mutable_literals resolve ~ resolve_items_individually ~ get_typed_dictionary ~ expression ~ resolved ~ expected ~ comparator = let comparator_without_override = comparator in let comparator = comparator ~ get_typed_dictionary_override ( : fun _ -> None ) in let open Expression in match expression , resol... |
let weaken_mutable_literals = weaken_mutable_literals ~ resolve_items_individually : false |
type block = int array ; ; |
type objdata = | Present of block | Absent of int ; ; |
type bunch = { objs : objdata array ; wp : block Weak . t ; } ; ; |
let data = Array . init size ( fun i -> let n = 1 + Random . int size in { objs = Array . make n ( Absent 0 ) ; wp = Weak . create n ; } ) ; ; |
let gccount ( ) = ( Gc . quick_stat ( ) ) . Gc . major_collections ; ; |
let check_and_change i j = let gc1 = gccount ( ) in match data . ( i ) . objs . ( j ) , Weak . check data . ( i ) . wp j with | Present x , false -> assert false | Absent n , true -> assert ( gc1 <= n + 1 ) | Absent _ , false -> let x = Array . make ( 1 + Random . int 10 ) 42 in data . ( i ) . objs . ( j ) <- Present x... |
let dummy = ref [ ] ; ; || dummy := Array . make ( Random . int 300 ) 0 ; let i = Random . int size in let j = Random . int ( Array . length data . ( i ) . objs ) in check_and_change i j ; done |
let alive = ref ( Array . init n ( fun _ -> Array . make 10 0 ) ) |
let create_weaks ( ) = Array . init n ( fun i -> let w = Weak . create 1 in Weak . set w 0 ( Some ( ! alive . ( i ) ) ) ; w ) |
let weak1 = create_weaks ( ) |
let weak2 = create_weaks ( ) |
let weak3 = create_weaks ( ) |
let ( ) = let dummy = ref [ ] || in for l = 0 to 10 do dummy := Array . make 300 0 done |
let gccount ( ) = ( Gc . quick_stat ( ) ) . Gc . major_collections ; ; |
let ( ) = for _l = 1 to loop do let bad = ref 0 in for i = 0 to n - 1 do for _j = 0 to n * 10 do ignore ( Weak . get weak2 . ( i ) 0 ) ; done ; if Weak . check weak2 . ( i ) 0 && not ( Weak . check weak1 . ( i ) 0 ) && Weak . check weak2 . ( i ) 0 then incr bad ; if Weak . check weak2 . ( i ) 0 && not ( Weak . check we... |
let random_state = Domain . DLS . new_key Random . State . make_self_init |
let random_int = Random . State . int ( Domain . DLS . get random_state ) |
type block = int array ; ; |
type objdata = | Present of block | Absent of int ; ; |
type bunch = { objs : objdata array ; wp : block Weak . t ; } ; ; |
let data = Array . init size ( fun i -> let n = 1 + random_int size in { objs = Array . make n ( Absent 0 ) ; wp = Weak . create n ; } ) ; ; |
let gccount ( ) = let res = ( Gc . quick_stat ( ) ) . Gc . major_collections in res |
type change = No_change | Fill | Erase ; ; |
let check_and_change data i j = let gc1 = gccount ( ) in let change = match data . ( i ) . objs . ( j ) , Weak . check data . ( i ) . wp j with | Present x , false -> assert false | Absent n , true -> assert ( gc1 <= n + 2 ) ; No_change | Absent _ , false -> Fill | Present _ , true -> if random_int 10 = 0 then Erase el... |
let dummy = ref [ ] ; ; || |
let run index ( ) = let domain_data = Array . init 100 ( fun i -> let n = 1 + random_int 100 in { objs = Array . make n ( Absent 0 ) ; wp = Weak . create n ; } ) in while gccount ( ) < 5 do dummy := Array . make ( random_int 300 ) 0 ; let i = ( random_int ( size / num_domains ) ) + index * size / num_domains in let j =... |
let _ = for index = 0 to 4 do let domains = Array . init ( num_domains - 1 ) ( fun i -> Domain . spawn ( run ( ( i + index ) mod 5 ) ) ) in run ( ( num_domains - 1 + index ) mod 5 ) ( ) ; Array . iter Domain . join domains done ; print_endline " ok " |
module type S = sig type data type t val create : int -> t val clear : t -> unit val merge : t -> data -> data val fold : ( data -> ' a -> ' a ) -> t -> ' a -> ' a val actually_weak : bool end |
module MakeStrong ( H : Hashtbl . HashedType ) = struct module Set = Set . Make ( struct type t = H . t let compare x y = if H . equal x y then 0 else let hx = H . hash x in let hy = H . hash y in hx - hy end ) type data = H . t type t = { mutable set : Set . t } let create n = { set = Set . empty } let clear s = s . s... |
module MakeWeak ( H : Hashtbl . HashedType ) = struct let actually_weak = true let limit = 8 type t = { mutable extent : int ; mutable array : H . t Weak . t ; } type data = H . t let is_array xs = Weak . length xs . array <= limit let create n = { extent = 0 ; array = Weak . create ( max 1 n ) } let clear xs = if is_a... |
module Hashed = struct type t = string list ; ; let equal x y = eprintf " equal : % s / % s \ n " ( List . hd x ) ( List . hd y ) ; x = y ; ; let hash x = Hashtbl . hash ( List . hd x ) ; ; end ; ; |
module HT = Weak . Make ( Hashed ) ; ; |
let tbl = HT . create 7 ; ; |
let r = ref [ ] ; ; |
let bunch = if Array . length Sys . argv < 2 then 10000 else int_of_string Sys . argv . ( 1 ) ; ; |
let random_string n = String . init n ( fun _ -> Char . chr ( 32 + Random . int 95 ) ) ; ; |
let added = ref 0 ; ; |
let mistakes = ref 0 ; ; |
let print_status ( ) = let ( len , entries , sumbuck , buckmin , buckmed , buckmax ) = HT . stats tbl in if entries > bunch * ( ! added + 1 ) then begin if debug then begin printf " \ n ===================\ n " ; printf " len = % d \ n " len ; printf " entries = % d \ n " entries ; printf " sum of bucket sizes = % d \ ... |
module type G = sig type t module V : Sig . COMPARABLE val iter_vertex : ( V . t -> unit ) -> t -> unit val iter_succ : ( V . t -> unit ) -> t -> V . t -> unit end |
type ' a element = | Vertex of ' a | Component of ' a * ' a t |
module Make ( G : G ) = struct module HT = Hashtbl . Make ( G . V ) let recursive_scc g root_g = let stack = Stack . create ( ) in let dfn = HT . create 1024 in let num = ref 0 in let partition = ref [ ] in G . iter_vertex ( fun v -> HT . add dfn v 0 ) g ; let rec visit vertex partition = let head = ref 0 in let loop =... |
module Component = struct type t = { id : int ; kind : kind ; } [ @@ deriving compare , sexp ] and kind = | Node of Cfg . Node . t | Cycle of { head : Cfg . Node . t ; components : t list ; } [ @@ deriving compare , sexp ] end |
type t = Component . t list [ @@ deriving compare , sexp ] |
let create ~ cfg ~ entry_index ~ successors = let depth_first_numbers = Int . Table . create ( ) in let stack = Stack . create ( ) in let current_depth_first_number = ref 0 in let make_depth_first_number ( ) = incr current_depth_first_number ; ! current_depth_first_number in let get_depth_first_number node_index = Hash... |
let assert_wto ( ? entry_index = 0 ) cfg_nodes expected_wto = let cfg = Int . Table . create ( ) in let insert_node node = Hashtbl . set cfg ~ key ( : Cfg . Node . id node ) ~ data : node in List . iter ~ f : insert_node cfg_nodes ; let actual_wto = WeakTopologicalOrder . create ~ cfg ~ entry_index ~ successors : Cfg .... |
let cfg_node ( ? predecessors = [ ] ) ( ? successors = [ ] ) id = Cfg . Node . create id Cfg . Node . Normal ( Int . Set . of_list predecessors ) ( Int . Set . of_list successors ) |
let wto_node id = { WeakTopologicalOrder . Component . id = 0 ; kind = Node ( cfg_node id ) } |
let wto_cycle ~ head ~ components = { WeakTopologicalOrder . Component . id = 0 ; kind = Cycle { head = cfg_node head ; components } } |
let test_empty _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ ] ] : [ wto_node 0 ] |
let test_sequential _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ] ~ successors [ : 2 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 3 ] ; cfg_node 3 ~ predecessors [ : 2 ] ~ successors [ ] ; : ] [ wto_node 0 ; wto_node 1 ; wto_node 2 ; wto_node 3 ] |
let test_branch _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ] ~ successors [ : 2 ; 3 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 4 ] ; cfg_node 3 ~ predecessors [ : 1 ] ~ successors [ : 4 ] ; cfg_node 4 ~ predecessors [ : 2 ; 3 ] ~ successors [ ] ; ... |
let test_nested_branch _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ] ~ successors [ : 2 ; 3 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 4 ; 5 ] ; cfg_node 3 ~ predecessors [ : 1 ] ~ successors [ : 7 ] ; cfg_node 4 ~ predecessors [ : 2 ] ~ successors... |
let test_unreachable _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 2 ] ; cfg_node 1 ~ predecessors [ : 3 ] ~ successors [ : 2 ] ; cfg_node 2 ~ predecessors [ : 0 ; 1 ] ~ successors [ ] ; : cfg_node 3 ~ predecessors [ ] : ~ successors [ : 1 ] ; ] [ wto_node 0 ; wto_node 2 ] |
let test_loop _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ; 2 ] ~ successors [ : 2 ; 3 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 1 ] ; cfg_node 3 ~ predecessors [ : 1 ] ~ successors [ ] ; : ] [ wto_node 0 ; wto_cycle ~ head : 1 ~ components [ : wt... |
let test_loop_with_branch _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ; 5 ] ~ successors [ : 2 ; 6 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 3 ; 4 ] ; cfg_node 3 ~ predecessors [ : 2 ] ~ successors [ : 5 ] ; cfg_node 4 ~ predecessors [ : 2 ] ~ suc... |
let test_nested_loop _ = assert_wto [ cfg_node 0 ~ predecessors [ ] : ~ successors [ : 1 ] ; cfg_node 1 ~ predecessors [ : 0 ; 4 ] ~ successors [ : 2 ; 3 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 4 ; 5 ] ; cfg_node 3 ~ predecessors [ : 1 ] ~ successors [ ] ; : cfg_node 4 ~ predecessors [ : 2 ] ~ successors... |
let test_bourdon _ = assert_wto ~ entry_index : 1 [ cfg_node 1 ~ predecessors [ ] : ~ successors [ : 2 ] ; cfg_node 2 ~ predecessors [ : 1 ] ~ successors [ : 3 ; 8 ] ; cfg_node 3 ~ predecessors [ : 2 ; 7 ] ~ successors [ : 4 ] ; cfg_node 4 ~ predecessors [ : 3 ] ~ successors [ : 5 ; 7 ] ; cfg_node 5 ~ predecessors [ : ... |
let ( ) = " weakTopologicalOrder " >::: [ " empty " >:: test_empty ; " sequential " >:: test_sequential ; " branch " >:: test_branch ; " nested_branch " >:: test_nested_branch ; " unreachable " >:: test_unreachable ; " loop " >:: test_loop ; " loop_with_branch " >:: test_loop_with_branch ; " nested_loop " >:: test_nest... |
type ( ' a , ' b ) t = { entry_by_key : ( ' a , ' b Weak_pointer . t ) Hashtbl . t ; keys_with_unused_data : ' a Thread_safe_queue . t ; mutable thread_safe_run_when_unused_data : unit -> unit } |
module Using_hashable = struct let create ? growth_allowed ? size hashable = { entry_by_key = Hashtbl . Using_hashable . create ~ hashable ? growth_allowed ? size ( ) ; keys_with_unused_data = Thread_safe_queue . create ( ) ; thread_safe_run_when_unused_data = ignore } ; ; end |
let create ? growth_allowed ? size m = Using_hashable . create ? growth_allowed ? size ( Hashtbl . Hashable . of_key m ) ; ; |
let set_run_when_unused_data t ~ thread_safe_f = t . thread_safe_run_when_unused_data <- thread_safe_f ; ; ; |
let remove t key = Hashtbl . remove t . entry_by_key key |
let reclaim_space_for_keys_with_unused_data t = while Thread_safe_queue . length t . keys_with_unused_data > 0 do let key = Thread_safe_queue . dequeue_exn t . keys_with_unused_data in match Hashtbl . find t . entry_by_key key with | None -> ( ) | Some entry -> if Weak_pointer . is_none entry then remove t key done ; ;... |
let get_entry t key = Hashtbl . find_or_add t . entry_by_key key ~ default ( : fun ( ) -> Weak_pointer . create ( ) ) ; ; ; |
let mem t key = match Hashtbl . find t . entry_by_key key with | None -> false | Some entry -> Weak_pointer . is_some entry ; ; |
let key_is_using_space t key = Hashtbl . mem t . entry_by_key key |
let set_data t key entry data = Weak_pointer . set entry data ; Gc . Expert . add_finalizer_last data ( fun ( ) -> Thread_safe_queue . enqueue t . keys_with_unused_data key ; t . thread_safe_run_when_unused_data ( ) ) ; ; ; |
let replace t ~ key ~ data = set_data t key ( get_entry t key ) data |
let add_exn t ~ key ~ data = let entry = get_entry t key in if Weak_pointer . is_some entry then failwiths ~ here [ :% here ] " Weak_hashtbl . add_exn of key in use " t [ % sexp_of : ( _ , _ ) t ] ; set_data t key entry data ; ; ; |
let find t key = match Hashtbl . find t . entry_by_key key with | None -> None | Some entry -> Weak_pointer . get entry ; ; |
let find_or_add t key ~ default = let entry = get_entry t key in match Weak_pointer . get entry with | Some v -> v | None -> let data = default ( ) in set_data t key entry data ; data ; ; |
let create ? growth_allowed ? size hashable = let t = create ? growth_allowed ? size hashable in let reclaim_will_happen = ref false in let reclaim ( ) = reclaim_will_happen := false ; reclaim_space_for_keys_with_unused_data t in set_run_when_unused_data t ~ thread_safe_f ( : fun ( ) -> if not ! reclaim_will_happen the... |
let reclaim_space_for_keys_with_unused_data ` Do_not_use = assert false |
let set_run_when_unused_data ` Do_not_use = assert false |
type t = out_channel -> LP . doc -> unit |
let ( ) @@ f x = f x |
module Markdown = struct let output_code io = String . iter ( function | ' \ n ' -> output_string io " \ n " | c -> output_char io c ) let code io = function | LP . Str ( _ , str ) -> output_code io str | LP . Ref ( str ) -> fprintf io " <<% s " >> str let chunk io = function | LP . Doc ( str ) -> output_string io str ... |
let formats = let add map ( keys , value ) = List . fold_left ( fun m k -> SM . add k value m ) map keys in List . fold_left add SM . empty [ [ " plain " ; " markdown " ] , Markdown . weave ] |
let lookup fmt = try SM . find fmt formats with Not_found -> raise ( NoSuchFormat fmt ) |
let formats = List . map fst @@ SM . bindings formats |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.