text stringlengths 12 786k |
|---|
let get_replace typ = match ( repr typ ) . type_desc with Treplace typ -> Some typ | _ -> None |
let get_rev_arrow_args typ = let rec go args typ = let typ = repr typ in match typ . type_desc with | Tarrow ( typ1 , typ2 , explicit , label ) -> go ( ( typ1 , explicit , label ) :: args ) typ2 | _ -> ( args , typ ) in go [ ] typ |
let rec get_rev_implicits acc typ = match typ . type_desc with | Tarrow ( typ1 , typ2 , Implicit , label ) -> get_rev_implicits ( ( label , typ1 ) :: acc ) typ2 | _ -> ( acc , typ ) |
let get_implicits typ = let implicits , typ = get_rev_implicits [ ] typ in ( List . rev implicits , typ ) |
let get_rev_implicits typ = get_rev_implicits [ ] typ |
let contains typ ~ in_ = let typ = repr typ in let equal in_ = phys_equal typ ( repr in_ ) in let rec contains in_ = let in_ = repr in_ in match in_ . type_desc with | Tvar _ -> false | Ttuple typs -> List . exists ~ f : equal typs || List . exists ~ f : contains typs | Tarrow ( typ1 , ty... |
let rec get_same_mode typ1 typ2 = let typ1 = repr typ1 in let typ2 = repr typ2 in match ( typ1 . type_desc , typ2 . type_desc ) with | Tother_mode typ1 ' , Tother_mode typ2 ' -> ( match ( typ1 . type_mode , typ2 . type_mode ) with | Checked , Checked | Prover , Prover -> get_same... |
let rec remove_opaques typ = let typ = repr typ in match typ . type_desc with Topaque typ -> remove_opaques typ | _ -> typ |
let rec remove_mode_changes typ = let typ = repr typ in match typ . type_desc with | Tother_mode typ -> remove_mode_changes typ | _ -> typ |
module Decl = struct let decl_id = ref 0 let next_id ( ) = incr decl_id ; ! decl_id let mk ~ name ~ params desc = incr decl_id ; let tdec_ret = Mk . ctor ~ mode ( : Ident . mode name ) 10000 ( Path . Pident name ) params in { tdec_params = params ; tdec_desc = desc ; tdec_id =... |
let report_error ppf = function | Mk_wrong_mode ( kind , typs , mode , typ ) -> fprintf ppf " [ @< hov > Internal error : Could not make a type % s from types ; @\ [ @< hov2 >% a ] ; @@\ The type % a was expected to have mode % a . ] " @ kind ( pp_print_list ~ pp_sep : pp_p... |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer loc report_error err ) | _ -> None ) |
let shared_computation = Bonsai_web_ui_typeahead . Typeahead . create ( module Data ) ~ all_options ( : Value . return Data . all ) ~ placeholder " : Select a value " ~ to_string ( : Bonsai . Value . return Data . to_string ) ; ; |
let view_computation = let % sub _ , view , _ = shared_computation in return view ; ; |
let view_and_inject_computation = let % sub _ , view , inject = shared_computation in return ( Value . both view inject ) ; ; |
let view_and_result_computation = let % sub result , view , _ = shared_computation in return ( Value . both view result ) ; ; let handle = Handle . create ( Result_spec . vdom Fn . id ) view_computation in Handle . show handle ; [ % expect { | < div > < input type " = text "... |
let shared_computation = Bonsai_web_ui_typeahead . Typeahead . create_multi ( module Data ) ~ all_options ( : Value . return Data . all ) ~ placeholder " : Select a value " ~ to_string : Data . to_string ~ split ( : String . split ~ on ' , ' ) : ; ; |
let view_computation = let % sub _ , vdom , _ = shared_computation in return vdom ; ; |
let view_and_set_computation = let % sub _ , vdom , set = shared_computation in return ( Value . both vdom set ) ; ; |
let view_and_result_computation = let % sub result , vdom , _ = shared_computation in return ( Value . both vdom result ) ; ; |
let input_value handle value = Handle . input_text handle ~ get_vdom : Fn . id ~ selector " : input " ~ text ( : Data . to_string value ) ; ; let handle = Handle . create ( Result_spec . vdom Fn . id ) view_computation in Handle . show handle ; [ % expect { | < div > < i... |
let preprocess ~ pp ~ ext text = let sourcefile = Filename . temp_file " caml " ext in begin try let oc = open_out_bin sourcefile in output_string oc text ; flush oc ; close_out oc with _ -> failwith " Preprocessing error " end ; let tmpfile = Filename . temp_file " camlpp " ext in let com... |
let parse_pp ~ parse ~ wrap ~ ext text = match ! Clflags . preprocessor with None -> parse ( Lexing . from_string text ) | Some pp -> let tmpfile = preprocess ~ pp ~ ext text in let ast_magic = if ext = " . ml " then Config . ast_impl_magic_number else Config . ast_intf_magic_number in le... |
let nowarnings = ref false |
let f txt = let error_messages = ref [ ] in let text = Jg_text . get_all txt . tw and env = ref ( Env . open_pers_signature " Pervasives " Env . initial ) in let tl , ew , end_message = Jg_message . formatted ~ title " : Warnings " ~ ppf : Format . err_formatter ( ) in Text ... |
type error = [ ` TypeMismatchError of string | ` UnboundRegularVarInsideBoxError of Location . t * string | Env . error ] |
type ' e lerror = ( [ > error ] as ' e ) Location . located |
let check_equal ty1 ty2 msg = Result . ok_if_true ( [ % equal : Type . t ] ty1 ty2 ) ~ error ( ` : TypeMismatchError msg ) |
let with_error_location loc r = Result . map_error r ~ f ( : fun e -> Location . locate ~ loc e ) |
let fail_in loc err = Result . fail @@ Location . locate ~ loc @@ err |
let mk_unbound_regular_var_inside_box_error box_expr_loc var_loc var = let var_name = Id . R . to_string var in let msg = [ % string " regular variable " ( \$ var_name ) " \ is accessed in box expression \ ( ( $ Location . pp_column_range box_expr_loc ) ) at \ ( $ Location . pp_c... |
let rec check_open delta gamma Location . { data = expr ; loc } typ = match expr with | Unit -> let exp_ty = PrettyPrinter . Str . of_type typ in with_error_location loc @@ check_equal typ Type . Unit [ % string " Expected $ exp_ty , but found Unit type " ] | Pair { e1 ; e2 } -> ... |
let check expr typ = check_open Env . M . emp Env . R . emp expr typ |
let infer expr = infer_open Env . M . emp Env . R . emp expr |
type method_type = typ list * typ |
type method_env = method_type SM . t |
type attribute_env = typ SM . t |
type class_type = attribute_env * method_env |
type class_env = class_type SM . t |
type variable_env = typ SM . t |
let error ( location : ' a Location . t ) ( msg : string ) = raise ( Error ( sprintf " % s :\ n % s " ( Error . positions ( Location . startpos location ) ( Location . endpos location ) ) msg ) ) |
let errors ( locations : ' a Location . t list ) ( msg : string ) = raise ( Error ( sprintf " % s % s " ( List . fold_right ( fun location acc -> sprintf " % s :\ n % s " ( Error . positions ( Location . startpos location ) ( Location . endpos location ) ) acc ) ... |
let lookup ( msg : string ) ( id : identifier ) ( env : ' a SM . t ) = try SM . find ( Location . content id ) env with Not_found -> error id ( sprintf " % s % s is undefined " msg ( Location . content id ) ) |
let vlookup : identifier -> variable_env -> typ = lookup " variable " |
let mlookup : identifier -> method_env -> method_type = lookup " method " |
let alookup : identifier -> attribute_env -> typ = lookup " attribute " |
let clookup : identifier -> class_env -> class_type = lookup " class " |
let rec compatible ( typ1 : typ ) ( typ2 : typ ) ( instanceof : identifier -> identifier -> bool ) : bool = match typ1 , typ2 with | TypInt , TypInt | TypBool , TypBool | TypIntArray , TypIntArray -> true | Typ t1 , Typ t2 -> instanceof t1 t2 | _ , _ -> false |
let rec type_to_string : typ -> string = function | TypInt -> " integer " | TypBool -> " boolean " | TypIntArray -> " int [ ] " | Typ t -> Location . content t |
let rec typecheck_call ( cenv : class_env ) ( venv : variable_env ) ( vinit : S . t ) ( instanceof : identifier -> identifier -> bool ) ( o : expression ) ( callee : identifier ) ( expressions : expression list ) : typ = let o_type = typecheck_expression cenv venv vinit instanc... |
let rec typecheck_instruction ( cenv : class_env ) ( venv : variable_env ) ( vinit : S . t ) ( instanceof : identifier -> identifier -> bool ) ( inst : instruction ) : S . t = match inst with | ISetVar ( v , e ) -> let vinit = S . add ( Location . content v ) vinit in t... |
let occurrences ( x : string ) ( bindings : ( identifier * ' a ) list ) : identifier list = List . map fst ( List . filter ( fun ( id , _ ) -> x = Location . content id ) bindings ) |
let map_of_association_list ( entity : string ) ( bindings : ( identifier * ' a ) list ) : ' a SM . t = try SM . of_association_list ( List . map ( fun ( id , data ) -> ( Location . content id , data ) ) bindings ) with SM . Duplicate x -> errors ( occurrences x bi... |
let variable_map ( decls : ( identifier * typ ) list ) : variable_env = map_of_association_list " Variable " decls |
let method_map ( decls : ( identifier * method_type ) list ) : method_env = map_of_association_list " Method " decls |
let typecheck_method ( cenv : class_env ) ( venv : variable_env ) ( instanceof : identifier -> identifier -> bool ) ( m : metho ) : unit = let formals = m . formals and locals = m . locals in let mformals = variable_map formals and mlocals = variable_map locals in begin try let x = Stri... |
let typecheck_class ( cenv : class_env ) ( instanceof : identifier -> identifier -> bool ) ( ( name , c ) : identifier * clas ) : unit = let attribute_env , _ = clookup name cenv in let venv = SM . add " this " ( Typ name ) attribute_env in List . iter ( typecheck_method cen... |
let extract_method_type ( m : metho ) : method_type = ( List . map snd m . formals , m . result ) |
let extract_class_type ( c : clas ) : class_type = ( variable_map c . attributes , method_map ( List . map ( fun ( id , m ) -> ( id , extract_method_type m ) ) c . methods ) ) |
let class_map ( decls : ( identifier * clas ) list ) : clas SM . t = map_of_association_list " Class " decls |
let create_instanceof ( cmap : clas SM . t ) : identifier -> identifier -> bool = let rec instanceof id1 id2 = if id1 = id2 then true else try match ( SM . find id1 cmap ) . extends with | None -> false | Some id3 -> instanceof ( Location . content id3 ) id2 with Not_found -> false in fu... |
let add_method ( cmap : clas SM . t ) ( instanceof : identifier -> identifier -> bool ) : clas SM . t = let test_compatible_signature ( ( name , m ) : identifier * metho ) ( ( name ' , m ' ) : identifier * metho ) : unit = let typecheck_params ( typ : typ ) ( typ '... |
let typecheck_program ( p : program ) : unit = let cmap = class_map p . defs in let instanceof = create_instanceof cmap in let cenv = add_method cmap instanceof |> SM . map extract_class_type in List . iter ( typecheck_class cenv instanceof ) p . defs ; let venv = SM . singleton " this " ... |
module DefaultContext = struct let qualifier = Reference . empty let constraint_solving_style = Configuration . Analysis . default_constraint_solving_style let debug = false let define = + Test . mock_define let resolution_fixpoint = None let error_map = None module Builder = Callgraph . NullBuilder ... |
let create_annotation_store ( ? immutables = [ ] ) annotations = let immutables = String . Map . of_alist_exn immutables in let annotify ( name , annotation ) = let annotation = let create annotation = match Map . find immutables name with | Some original -> Refinement . Unit . create (... |
let assert_annotation_store ~ expected actual = let actual = Resolution . annotation_store actual in let compare_annotation_store { Refinement . Store . annotations = left_annotations ; temporary_annotations = left_temporary_annotations ; } { Refinement . Store . annotations = right_annotation... |
module Create ( Context : TypeCheck . Context ) = struct let create ( ? bottom = false ) ( ? immutables = [ ] ) ~ resolution annotations = let module State = State ( Context ) in if bottom then State . unreachable else let resolution = let annotation_store = create_annotation_store ~... |
let description ~ resolution error = let ast_environment = Resolution . global_resolution resolution |> GlobalResolution . ast_environment in Error . instantiate ~ show_error_traces : false ~ lookup ( : AstEnvironment . ReadOnly . get_relative ast_environment ) error |> Error . Instantiated . ... |
let test_initial context = let assert_initial ? parent ( ? environment = " " ) ( ? immutables = [ ] ) ~ annotations define = let define = match parse_single_statement define with | { Node . value = Define ( { signature ; _ } as define ) ; _ } -> let signature = { signa... |
let test_less_or_equal context = let resolution = ScratchProject . setup ~ context [ ] |> ScratchProject . build_resolution in let create = let module Create = Create ( DefaultContext ) in Create . create ~ resolution in let module State = State ( DefaultContext ) in assert_true ( State . ... |
let test_widen context = let resolution = ScratchProject . setup ~ context [ ] |> ScratchProject . build_resolution in let create = let module Create = Create ( DefaultContext ) in Create . create ~ resolution in let module State = State ( DefaultContext ) in let assert_state_equal = assert_e... |
let test_check_annotation context = let assert_check_annotation source variable_name descriptions = let resolution = ScratchProject . setup ~ context [ " test . py " , source ] |> ScratchProject . build_resolution in let module State = State ( DefaultContext ) in let errors = let expression ... |
let assert_resolved ~ context sources expression expected = let resolution = ScratchProject . setup ~ context sources |> ScratchProject . build_resolution in let resolved = Resolution . resolve_expression_to_type resolution ( parse_single_expression expression ) in assert_equal ~ printer : Type . sh... |
let test_module_exports context = let assert_exports_resolved expression expected = let sources = [ " implementing . py " , { | def function ( ) -> int : . . . constant : int = 1 } ; | ( " exporting . py " , { | from implementing import function , constant from impleme... |
let test_object_callables context = let assert_resolved expression annotation = assert_resolved ~ context [ ( " module . py " , { | _K = typing . TypeVar ( ' _K ' ) _V = typing . TypeVar ( ' _V ' ) _T = typing . TypeVar ( ' _T ' ) class object : def __init__ ( ... |
let test_callable_selection context = let assert_resolved source expression annotation = assert_resolved ~ context [ " test . py " , source ] expression ( Type . create ~ aliases : Type . empty_aliases ( parse_single_expression annotation ) ) in assert_resolved " call : typing . Callab... |
type parameter_kind = | NamedParameter | VariableParameter | KeywordParameter |
let test_forward_expression context = let assert_forward ( ? precondition = [ ] ) ( ? postcondition = [ ] ) ( ? environment = " " ) expression annotation = let expression = let expression = parse expression |> Preprocessing . preprocess in expression |> function | { Source . s... |
let test_forward_statement context = let global_resolution = ScratchProject . setup ~ context [ ] |> ScratchProject . build_global_resolution in let assert_forward ( ? precondition_immutables = [ ] ) ( ? postcondition_immutables = [ ] ) ( ? bottom = false ) precondition statement p... |
let test_forward context = let resolution = ScratchProject . setup ~ context [ ] |> ScratchProject . build_resolution in let create = let module Create = Create ( DefaultContext ) in Create . create ~ resolution in let module State = State ( DefaultContext ) in let assert_state_equal = assert... |
type method_call = { direct_target : string ; class_name : string ; dispatch : Callgraph . dispatch ; is_optional_class_attribute : bool ; } |
type property_setter_call = { direct_target : string ; class_name : string ; } |
let function_caller name = Callgraph . FunctionCaller !& name |
let property_setter_caller name = Callgraph . PropertySetterCaller !& name |
let test_calls context = let assert_calls source calls = let project = ScratchProject . setup ~ context [ " qualifier . py " , source ] in let _ = ScratchProject . build_type_environment project in let assert_calls ( caller , callees ) = let expected_callees = let callee = function | ` ... |
let test_unpack_callable_and_self_argument context = let parse ~ global_resolution annotation = parse_single_expression ~ preprocess : true annotation |> GlobalResolution . parse_annotation global_resolution in let assert_unpack_type ( ? source = " " ) ~ signature_select given expected = let global_... |
let ( ) = " type " >::: [ " initial " >:: test_initial ; " less_or_equal " >:: test_less_or_equal ; " widen " >:: test_widen ; " check_annotation " >:: test_check_annotation ; " forward_expression " >:: test_forward_expression ; " forward_statement " >:: test_forward_... |
type ' a class_info = { cls_id : Ident . t ; cls_id_loc : string loc ; cls_decl : class_declaration ; cls_ty_id : Ident . t ; cls_ty_decl : class_type_declaration ; cls_obj_id : Ident . t ; cls_obj_abbr : type_declaration ; cls_typesharp_id : Ident . t ; cls_abbr : type_declaration... |
type class_type_info = { clsty_ty_id : Ident . t ; clsty_id_loc : string loc ; clsty_ty_decl : class_type_declaration ; clsty_obj_id : Ident . t ; clsty_obj_abbr : type_declaration ; clsty_typesharp_id : Ident . t ; clsty_abbr : type_declaration ; clsty_info : Typedtree . class_type_dec... |
type ' a full_class = { id : Ident . t ; id_loc : tag loc ; clty : class_declaration ; ty_id : Ident . t ; cltydef : class_type_declaration ; obj_id : Ident . t ; obj_abbr : type_declaration ; cl_id : Ident . t ; cl_abbr : type_declaration ; arity : int ; pub_meths : string l... |
type error = Unconsistent_constraint of Ctype . Unification_trace . t | Field_type_mismatch of string * string * Ctype . Unification_trace . t | Structure_expected of class_type | Cannot_apply of class_type | Apply_wrong_label of arg_label | Pattern_type_clash of type_expr | Repeated_parameter | Unbou... |
let type_open_descr : ( ? used_slot : bool ref -> Env . t -> Parsetree . open_description -> open_description * Env . t ) ref = ref ( fun ? used_slot : _ _ -> assert false ) |
let ctyp desc typ env loc = { ctyp_desc = desc ; ctyp_type = typ ; ctyp_loc = loc ; ctyp_env = env ; ctyp_attributes = [ ] } |
let unbound_class = Path . Pident ( Ident . create_local " * undef " ) * |
let rec scrape_class_type = function Cty_constr ( _ , _ , cty ) -> scrape_class_type cty | cty -> cty |
let rec generalize_class_type gen = function Cty_constr ( _ , params , cty ) -> List . iter gen params ; generalize_class_type gen cty | Cty_signature { csig_self = sty ; csig_vars = vars ; csig_inher = inher } -> gen sty ; Vars . iter ( fun _ ( _ , _ , ty ) -> gen ty ) v... |
let generalize_class_type vars = let gen = if vars then Ctype . generalize else Ctype . generalize_structure in generalize_class_type gen |
let virtual_methods sign = let ( fields , _ ) = Ctype . flatten_fields ( Ctype . object_fields sign . Types . csig_self ) in List . fold_left ( fun virt ( lab , _ , _ ) -> if lab = dummy_method then virt else if Concr . mem lab sign . csig_concr then virt else lab :: virt ) [... |
let rec constructor_type constr cty = match cty with Cty_constr ( _ , _ , cty ) -> constructor_type constr cty | Cty_signature _ -> constr | Cty_arrow ( l , ty , cty ) -> Ctype . newty ( Tarrow ( l , ty , constructor_type constr cty , Cok ) ) |
let rec class_body cty = match cty with Cty_constr _ -> cty | Cty_signature _ -> cty | Cty_arrow ( _ , _ , cty ) -> class_body cty |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.