text
stringlengths
12
786k
module Wrap = struct let ( <: ) name type_ = create ( name |> Symbol . intern ) type_ include ( Value . Type : Value . Type . S ) end
let symbol_as_value t = t . symbol |> Symbol . to_value
let default_value = Funcall . Wrap . ( " default - value " <: Symbol . t @-> return value )
let default_value_exn t = default_value t . symbol |> Value . Type . of_value_exn t . type_
let default_boundp = Funcall . Wrap . ( " default - boundp " <: Symbol . t @-> return bool )
let default_value_is_defined t = default_boundp t . symbol
let set_default = Funcall . Wrap . ( " set - default " <: Symbol . t @-> value @-> return nil )
let set_default_value t a = set_default t . symbol ( a |> Value . Type . to_value t . type_ )
let make_variable_buffer_local = Funcall . Wrap . ( " make - variable - buffer - local " <: Symbol . t @-> return nil ) ; ;
let make_buffer_local_always t = add_gc_root ( symbol_as_value t ) ; make_variable_buffer_local t . symbol ; ;
let local_variable_if_set_p = Funcall . Wrap . ( " local - variable - if - set - p " <: Symbol . t @-> Buffer . t @-> return bool ) ; ;
let is_buffer_local_if_set t buffer = local_variable_if_set_p t . symbol buffer
let is_buffer_local_always var = let buffer = Buffer . create ~ name " :* for [ Var . is_buffer_local_always ] " * in let result = is_buffer_local_if_set var buffer in Buffer . Blocking . kill buffer ; result ; ;
module And_value = struct type t = T : ' a var * ' a -> t [ @@ deriving sexp_of ] end
module And_value_option = struct type t = T : ' a var * ' a option -> t [ @@ deriving sexp_of ] end
let hash_variant s = let accu = ref 0 in for i = 0 to String . length s - 1 do accu := 223 * ! accu + Char . code s . [ i ] done ; accu := ! accu land ( 1 lsl 31 - 1 ) ; if ! accu > 0x3FFFFFFF then ! accu - 1 lsl 31 else ! accu
let lexer = make_lexer [ " " ; -> " " ] $$
let main ( ) = let s = lexer ( Stream . of_channel stdin ) in let tags = Hashtbl . create 57 in try while true do let ( strm__ : _ Stream . t ) = s in match Stream . peek strm__ with Some ( Ident tag ) -> Stream . junk strm__ ; print_string " # define MLTAG_ " ; print_string t...
let _ = Printexc . print main ( )
type t = ( Name . t * Kind . t ) t list
let to_string ( env : t ) t : string = [ " " ^ List . fold_left ( fun s ( name , k ) k -> s ^ " , " ^ Name . to_string name ^ " : " ^ Kind . to_string k ) k " " env ^ " ] "
let rec union ( env1 : t ) t ( env2 : t ) t : t = match env1 with | [ ] -> env2 | ( name , kind ) kind :: env -> ( match List . assoc_opt name env2 with | None -> ( name , kind ) kind :: union env env2 | Some kind ' -> let env2 = List . remove_assoc name env2 in let kind = ...
let unions ( envs : t list ) list : t = List . fold_left union [ ] envs
let reorg ( names : Name . t list ) list ( env : t ) t : t = names |> List . filter_map ( fun name -> match List . assoc_opt name env with | None -> None | Some kind -> Some ( name , kind ) kind ) kind
let rec group_by_kind_aux ( env : t ) t ( kind : Kind . t ) t : ( Kind . t * Name . t list ) list list * Name . t list * Kind . t = match env with | [ ] -> ( [ ] , [ ] , kind ) kind | [ ( name , k ) k ] -> ( [ ] , [ name ] , k ) k | ( name ,...
let group_by_kind ( env : t ) t : ( Kind . t * Name . t list ) list list = match env with | [ ] -> [ ] | [ ( name , k ) k ] -> [ ( k , [ name ] ) ] | ( name , k ) k :: ls -> let ls , names , k ' = group_by_kind_aux ls k in if k = k ' then ( k , n...
let remove ( keys : Name . t list ) list ( env : t ) t : t = env |> List . filter ( fun ( name , _ ) _ -> not ( List . mem name keys ) keys ) keys
let keep_only ( keys : Name . t list ) list ( env : t ) t : t = env |> List . filter ( fun ( name , _ ) _ -> List . mem name keys ) keys
module Spec = struct exception Top include Analyses . DefaultSpec module D = struct include PartitionDomain . ExpPartitions let invariant c ss = fold ( fun s a -> if B . mem MyCFG . unknown_exp s then a else let module B_prod = BatSet . Make2 ( Exp ) ( Exp ) in let s_prod = B_prod . cartesia...
let _ = MCP . register_analysis ( module Spec : MCPSpec )
type t = { compilation_unit : Compilation_unit . t ; name : string ; name_stamp : int ; } type nonrec t = t let compare t1 t2 = if t1 == t2 then 0 else let c = t1 . name_stamp - t2 . name_stamp in if c <> 0 then c else Compilation_unit . compare t1 . compilation_unit t2 . compilation_u...
let previous_name_stamp = ref ( - 1 )
let create_with_name_string ? current_compilation_unit name = let compilation_unit = match current_compilation_unit with | Some compilation_unit -> compilation_unit | None -> Compilation_unit . get_current_exn ( ) in let name_stamp = incr previous_name_stamp ; ! previous_name_stamp in { compilation_u...
let create ? current_compilation_unit name = let name = ( name : Internal_variable_names . t :> string ) in create_with_name_string ? current_compilation_unit name
let create_with_same_name_as_ident ident = create_with_name_string ( Ident . name ident )
let rename ? current_compilation_unit t = create_with_name_string ? current_compilation_unit t . name
let in_compilation_unit t cu = Compilation_unit . equal cu t . compilation_unit
let get_compilation_unit t = t . compilation_unit
let name t = t . name
let unique_name t = t . name ^ " _ " ^ ( Int . to_string t . name_stamp )
let print_list ppf ts = List . iter ( fun t -> Format . fprintf ppf " @ % a " print t ) ts
let debug_when_stamp_matches t ~ stamp ~ f = if t . name_stamp = stamp then f ( )
let print_opt ppf = function | None -> Format . fprintf ppf " < no var " > | Some t -> print ppf t
type pair = t * t
module Pair = Identifiable . Make ( Identifiable . Pair ( T ) ( T ) )
let compare_lists l1 l2 = Misc . Stdlib . List . compare compare l1 l2
let output_full chan t = Compilation_unit . output chan t . compilation_unit ; output_string chan " . " ; output chan t
type exporter = value -> string
type t = { variable_name : string ; variable_description : string ; variable_exporter : exporter }
let compare v1 v2 = String . compare v1 . variable_name v2 . variable_name
let default_exporter varname value = Printf . sprintf " % s =% s " varname value
let make ( name , description ) = if name " " = then raise Empty_variable_name else { variable_name = name ; variable_description = description ; variable_exporter = default_exporter name }
let make_with_exporter exporter ( name , description ) = if name " " = then raise Empty_variable_name else { variable_name = name ; variable_description = description ; variable_exporter = exporter }
let name_of_variable v = v . variable_name
let description_of_variable v = v . variable_description
let ( variables : ( string , t ) Hashtbl . t ) = Hashtbl . create 10
let register_variable variable = if Hashtbl . mem variables variable . variable_name then raise ( Variable_already_registered variable . variable_name ) else Hashtbl . add variables variable . variable_name variable
let find_variable variable_name = try Some ( Hashtbl . find variables variable_name ) with Not_found -> None
let string_of_binding variable value = variable . variable_exporter value
let get_registered_variables ( ) = let f _variable_name variable variable_list = variable :: variable_list in List . sort compare ( Hashtbl . fold f variables [ ] )
let suite : ( string * [ ` > Quick ] * ( unit -> unit ) ) list = [ ( " nullable " , ` Quick , fun ( ) -> let _ , mk_variables , _ = [ % graphql { | query Foo ( $ int : Int , $ string : String , $ bool : Boolean , $ float : Float , $ id : ID , $ ...
let test_query variables = Test_common . test_query Echo_schema . schema ( ) ~ variables
let suite : ( string * [ > ` Quick ] * ( unit -> unit ) ) list = [ ( " string variable " , ` Quick , fun ( ) -> let variables = [ ( " x " , ` String " foo bar baz " ) ] in let query = " { string ( x : $ x ) } " in test_query variables query ( ...
module Operation = struct module T = struct type t = | Set | Let | Unlet | Makunbound | Defvaralias [ @@ deriving enumerate , sexp_of ] end include T let type_ = Value . Type . enum [ % message " variable - change - operation " ] ( module T ) ( ( function | Set -> " set " |...
module Event = struct type t = { local_to_buffer : Buffer . t option ; new_value : Value . t ; operation : Operation . t ; variable_changed : Symbol . t } [ @@ deriving sexp_of ] end
let build_function here f = Defun . lambda here ( Returns Value . Type . unit ) ( let % map_open . Defun ( ) = return ( ) and symbol = required " symbol " Symbol . type_ and newval = required " newval " Value . Type . value and operation = required " operation " Operation ....
type t = { symbol : Symbol . t ; watcher : Function . t }
let add_variable_watcher = Funcall . Wrap . ( " add - variable - watcher " <: Symbol . type_ @-> Function . type_ @-> return nil ) ; ;
let add here var ~ f = let watcher = build_function here f in add_variable_watcher ( Var . symbol var ) watcher ; { symbol = Var . symbol var ; watcher } ; ;
let remove_variable_watcher = Funcall . Wrap . ( " remove - variable - watcher " <: Symbol . type_ @-> Function . type_ @-> return nil ) ; ;
let remove { symbol ; watcher } = remove_variable_watcher symbol watcher
let test_check_variance context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | def narnia ( ) : pass def foo ( ) -> None : [ narnia ( ) ] + [ 2 ] } | [ " Missing return annotation [ 3 ] : Returning ` None ` but no return type is specifie...
let test_check_literal_variance context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing x : typing . List [ float ] = [ ] x = [ 1 ] } | [ ] ; assert_type_errors { | import typing x : typing . List [ float ] = [ ] x = [ y ...
let ( ) = " variance " >::: [ " check_variance " >:: test_check_variance ; " check_literal_variance " >:: test_check_literal_variance ; ] |> Test . run
module rec X : sig type t = int * bool type t = A | B let f = function A | B -> 0 end ; ; [ %% expect { | Modules do not match : sig type t = X . t = A | B val f : t -> int end is not included in sig type t = int * bool end Type declarations do not match : type t = X . t = A | B is no...
module Make ( X : sig val f : [ ` A ] -> unit end ) = struct let make f1 f2 arg = match arg with ` A -> f1 arg ; f2 arg let f = make X . f ( fun _ -> ( ) ) end ; ; [ %% expect { |
module Make : functor ( X : sig val f : [ ` A ] -> unit end ) -> sig val make : ( ( [ < ` A ] as ' a ) -> ' b ) -> ( ' a -> ' c ) -> ' a -> ' c val f : [ ` A ] -> unit end } ] |
type ( ' a , ' b ) def = X of int constraint ' b = [ > ` A ]
type arity = ( int , [ ` A ] ) def = X of int ; ; [ %% expect { |
type ( ' a , ' b ) def = X of int constraint ' b = [ > ` A ] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( int , [ ` A ] ) def They have different arities . } ] |
type ( ' a , ' b ) ct = ( int , ' b ) def = X of int ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( int , [ > ` A ] ) def Their constraints differ . } ] |
type ( ' a , ' b ) kind = ( ' a , ' b ) def = { a : int } constraint ' b = [ > ` A ] ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( ' a , [ > ` A ] ) def Their kinds differ . } ] |
type d = X of int | Y of int
type missing = d = X of int [ %% expect { |
type d = X of int | Y of int ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The constructor Y is only present in the original definition . } ] |
type wrong_type = d = X of float [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Constructors do not match : X of int is not compatible with : X of float The types are not equal . } ] |
type unboxed = d = X of float [ @@ unboxed ] [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Their internal representations differ : this definition uses unboxed representation . } ] |
type perm = d = Y of int | X of int [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Constructors number 1 have different names , X and Y . } ] |
module M : sig type t = Foo of int type t = Foo : int -> t end ; ; [ %% expect { | Modules do not match : sig type t = Foo : int -> t end is not included in sig type t = Foo of int end Type declarations do not match : type t = Foo : int -> t is not included in type t = Foo of int Constructors d...
type ' a u = [ < ` a of int | ` b of bool & int & string > ` a ] as ' a
type ' a u1 = [ > ` a of int ] as ' a
type u2 = [ ` a of int ]
type ' a u3 = [ < ` b | ` a of & int & bool ] as ' a
type ' a u4 = [ < ` b | ` a of int & bool ] as ' a
module M1 : sig type t = | Foo of int * int type t = | Foo of float * int end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float * int end is not included in sig type t = Foo of int * int end Type declarations do not match : type t = Foo of float * int is not included in type ...
module M2 : sig type t = | Foo of int * int type t = | Foo of float end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float end is not included in sig type t = Foo of int * int end Type declarations do not match : type t = Foo of float is not included in type t = Foo of int * in...
module M3 : sig type t = | Foo of { x : int ; y : int } type t = | Foo of { x : float ; y : int } end ; ; [ %% expect { | Modules do not match : sig type t = Foo of { x : float ; y : int ; } end is not included in sig type t = Foo of { x : int ; y : int ; } end Type...
module M4 : sig type t = | Foo of { x : int ; y : int } type t = | Foo of float end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float end is not included in sig type t = Foo of { x : int ; y : int ; } end Type declarations do not match : type t = Foo of float is ...
module M5 : sig type ' a t = | Foo : int -> int t type ' a t = | Foo of ' a end ; ; [ %% expect { | Modules do not match : sig type ' a t = Foo of ' a end is not included in sig type ' a t = Foo : int -> int t end Type declarations do not match : type ' a t = Foo of ' a is not in...
module M : sig type ( ' a , ' b ) t = A of ' a type ( ' a , ' b ) t = A of ' b end ; ; Modules do not match : sig type ( ' a , ' b ) t = A of ' b end is not included in sig type ( ' a , ' b ) t = A of ' a end Type declarations do not match : type ( ' a , ...