text
stringlengths
0
601k
let subst x t ' = pre_subst ( subst_var x t ' ) ; ; [ %% expect { | } ] ; ; |
type ( _ , _ ) alist = | Anil : ( ' n , ' n ) alist | Asnoc : ( ' m , ' n ) alist * ' m term * ' m succ fin -> ( ' m succ , ' n ) alist
let rec sub : type m n . ( m , n ) alist -> m fin -> n term = function | Anil -> var | Asnoc ( s , t , x ) -> comp_subst ( sub s ) ( subst_var x t ) [ %% expect { |
type ( _ , _ ) alist = Anil : ( ' n , ' n ) alist | Asnoc : ( ' m , ' n ) alist * ' m term * ' m succ fin -> ( ' m succ , ' n ) alist } ] ; ; |
let rec append : type m n l . ( m , n ) alist -> ( l , m ) alist -> ( l , n ) alist = fun r s -> match s with | Anil -> r | Asnoc ( s , t , x ) -> Asnoc ( append r s , t , x ) [ %% expect { | } ] ; ; |
type _ ealist = EAlist : ( ' a , ' b ) alist -> ' a ealist
let asnoc a t ' x = EAlist ( Asnoc ( a , t ' , x ) ) [ %% expect { |
type _ ealist = EAlist : ( ' a , ' b ) alist -> ' a ealist < fun > } ] ; ; |
let rec weaken_fin : type n . n fin -> n succ fin = function | FZ -> FZ | FS x -> FS ( weaken_fin x )
let weaken_term t = pre_subst ( fun x -> Var ( weaken_fin x ) ) t
let rec weaken_alist : type m n . ( m , n ) alist -> ( m succ , n succ ) alist = function | Anil -> Anil | Asnoc ( s , t , x ) -> Asnoc ( weaken_alist s , weaken_term t , weaken_fin x )
let rec sub ' : type m . m ealist -> m fin -> m term = function | EAlist Anil -> var | EAlist ( Asnoc ( s , t , x ) ) -> comp_subst ( sub ' ( EAlist ( weaken_alist s ) ) ) ( fun t ' -> weaken_term ( subst_var x t t ' ) )
let subst ' d = pre_subst ( sub ' d ) ; ; [ %% expect { | } ] ; ; |
let flex_flex x y = match thick x y with | Some y ' -> asnoc Anil ( Var y ' ) x | None -> EAlist Anil
let flex_rigid x t = bind ( check x t ) ( fun t ' -> Some ( asnoc Anil t ' x ) )
let rec amgu : type m . m term -> m term -> m ealist -> m ealist option = fun s t acc -> match s , t , acc with | Leaf , Leaf , _ -> Some acc | Leaf , Fork _ , _ -> None | Fork _ , Leaf , _ -> None | Fork ( s1 , s2 ) , Fork ( t1 , t2 ) , _ -> bind ( amgu s1 t1 acc ) ( amgu s2 t2 ) | Var x , Var y , EAlist Anil -> let I...
let mgu s t = amgu s t ( EAlist Anil ) ; ; [ %% expect { | } ] ; ; |
let s = Fork ( Var FZ , Fork ( Var ( FS ( FS FZ ) ) , Leaf ) )
let t = Fork ( Var ( FS FZ ) , Var ( FS FZ ) )
let d = match mgu s t with Some x -> x | None -> failwith " mgu "
let s ' = subst ' d s
let t ' = subst ' d t ; ; [ %% expect { | EAlist ( Asnoc ( Asnoc ( Anil , Fork ( Var FZ , Leaf ) , FZ ) , Var FZ , FZ ) ) Fork ( Fork ( Var FZ , Leaf ) , Fork ( Var FZ , Leaf ) ) Fork ( Fork ( Var FZ , Leaf ) , Fork ( Var FZ , Leaf ) ) } ] ; ; |
let rec equal s t = match s , t with | T . Int , T . Int -> true | T . Bool , T . Bool -> true | T . Arrow ( t1 , t2 ) , T . Arrow ( s1 , s2 ) -> ( equal t1 s1 ) && ( equal t2 s2 ) | T . Product ss , T . Product ts -> List . for_all ( fun ( s , t ) -> equal s t ) ( List . combine ss ts ) | T . TVar { contents = Some s ...
let a1 : ( T . tp option ) ref = ref ( None ) ; ;
let a2 : ( T . tp option ) ref = ref ( None ) ; ;
let a3 : ( T . tp option ) ref = ref ( None ) ; ;
let a4 : ( T . tp option ) ref = ref ( None ) ; ;
let a5 : ( T . tp option ) ref = ref ( None ) ; ;
let a6 : ( T . tp option ) ref = ref ( None ) ; ;
let a7 : ( T . tp option ) ref = ref ( None ) ; ;
let a8 : ( T . tp option ) ref = ref ( None ) ; ;
let t1 = T . Arrow ( T . Product [ T . TVar ( a1 ) ; T . TVar ( a1 ) ] , T . TVar ( a2 ) ) ; ;
let t2 = T . Arrow ( T . Product [ T . Int ; T . Int ] , T . TVar ( a1 ) ) ; ;
let t3 = T . Arrow ( T . Product [ T . TVar ( a3 ) ; T . TVar ( a4 ) ] , T . TVar ( a4 ) ) ; ;
let t4 = T . Arrow ( T . Product [ T . TVar ( a4 ) ; T . TVar ( a3 ) ] , T . TVar ( a3 ) ) ; ;
let t5 = T . Arrow ( T . Product [ T . TVar ( a5 ) ; T . TVar ( a6 ) ] , T . TVar ( a6 ) ) ; ;
let t6 = T . Arrow ( T . TVar ( a6 ) , T . TVar ( a5 ) ) ; ;
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 . broadcast_message horseos username ) >>...
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 = { rw_enc_to_ucs : mappin...
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 = { rw_no_char = no_char ; rw_tbl = IMap...
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 = D . equal x y let startsta...
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 value with | Lambda { Lam...
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_to_identifier_node
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 ] | Delete expressions -> expressions | Assert { Assert ...
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 ) in state |> Map . data |> List . map ~ f : show_bin...
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 let fixpoint = Fixpoint . forward ...
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 { Scope . Scope . bindings ; globa...
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_uninitialized_errors { | def f ( y ) : x = y y = 5 } ...
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 h ( ) : if True : z = 1 else : assert ...
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 ...
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 " ) } , | [ ] ; { | assert True } , | [ ] ; { | return x } , | [ " x " , " 4 : 4...
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 Filename . dirname lib end else " / usr / local " )
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 " rm - vf % s / bin / oebuild % s . opt "...
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 [ @<>< name = % a ; barkVolume = % a ] " >@ Forma...
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 = ` Dog { name = " Fido " ; barkVolume = 123 . 0 } } equal pp
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_ % s " ud . ud_name else fprintf oc " Default_ % d...
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 \ n " ud . ud_mod ud . ud_name ud . ud_name
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 . ud_name c ; fprintf oc " { \ n " ; let pc = diver...
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 discr ud . ud_name c ; fprintf oc " { \ n " ; le...
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 ; data = x ; father = cell } in l ; h let rec find...
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 attribute type [ 8 ] : Attribute ` attr ` decl...
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 . int_to_js 1 | Enum_int_other x2 -> O...
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 . float_to_js 0 . 1 | Enum_float_1_1 -...
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 -> Enum_number_other x15 ) x15 fun ( x11 : 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 | _ -> Enum_number_other x20 ) x20 fun ( x16 : 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_string_foo -> Ojs . string_to_js " fo...
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 -> Ojs . bool_to_js 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 true
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 . bool_to_js true | Enum_bool...