text stringlengths 0 601k |
|---|
let classify_lazy_argument : Typedtree . expression -> [ ` Constant_or_function ` | Float_that_cannot_be_shortcut ` | Identifier of [ ` Forward_value ` | Other ] ` | Other ] = fun e -> match e . exp_desc with | Texp_constant ( Const_int _ | Const_char _ | Const_string _ | Const_int32 _ | Const_int64 _ | Const_nativeint... |
let value_kind_union k1 k2 = if k1 = k2 then k1 else Pgenval |
module type FullOrderTypeWithoutT = sig val always_less_or_equal : order -> left : Type . t -> right : Type . t -> bool val meet : order -> Type . t -> Type . t -> Type . t val join : order -> Type . t -> Type . t -> Type . t end |
module type FullOrderType = sig type t = order include FullOrderTypeWithoutT end |
module type OrderedConstraintsType = TypeConstraints . OrderedConstraintsType with type order = order |
module OrderImplementation = struct module Make ( OrderedConstraintsSet : ConstraintsSet . OrderedConstraintsSetType ) = struct type t = order let rec always_less_or_equal order ~ left ~ right = OrderedConstraintsSet . add ConstraintsSet . empty ~ new_constraint : ( LessOrEqual { left = Type . Variable . mark_all_varia... |
module rec Constraints : OrderedConstraintsType = TypeConstraints . OrderedConstraints ( Implementation ) ConstraintsSet . Make ( Constraints ) |
module IncludableImplementation : FullOrderTypeWithoutT = Implementation |
let rec is_compatible_with order ~ left ~ right = let fallback ( ) = always_less_or_equal order ~ left ~ right in match left , right with | _ , Type . Any | Type . Any , _ -> true | _ , Type . Top -> true | Type . Top , _ -> false | Type . NoneType , Type . NoneType -> true | Type . Tuple ( Concrete left ) , Type . Tup... |
let widen order ~ widening_threshold ~ previous ~ next ~ iteration = if iteration > widening_threshold then Type . Top else join order previous next |
let ( ! ) concretes = List . map concretes ~ f ( : fun single -> Type . Parameter . Single single ) |
let environment ? source context = let { ScratchProject . BuiltGlobalEnvironment . global_environment ; _ } = let sources = Option . value_map source ~ f ( : fun source -> [ " test . py " , source ] ) ~ default [ ] : in ScratchProject . setup ~ context sources |> ScratchProject . build_global_environment in global_envi... |
let resolution ? source context = let environment = environment ? source context in AnnotatedGlobalEnvironment . read_only environment |> GlobalResolution . create |
let concrete_connect ? parameters = let parameters = parameters >>| List . map ~ f ( : fun single -> Type . Parameter . Single single ) in MockClassHierarchyHandler . connect ? parameters |
let make_attributes ~ class_name = let parse_attribute ( name , annotation ) = Attribute . create ~ annotation ~ original_annotation : annotation ~ uninstantiated_annotation ( : Some annotation ) ~ visibility : ReadWrite ~ abstract : false ~ async_property : false ~ class_variable : false ~ defined : true ~ initialized... |
let parse_attributes ~ class_name ~ parse_annotation attributes = List . map attributes ~ f ( : fun ( name , annotation ) -> name , parse_annotation annotation ) |> make_attributes ~ class_name |
let get_typed_dictionary _ = None |
let hierarchy class_hierarchy_handler = { ConstraintsSet . instantiate_successors_parameters = ClassHierarchy . instantiate_successors_parameters class_hierarchy_handler ; is_transitive_successor = ClassHierarchy . is_transitive_successor class_hierarchy_handler ; variables = ClassHierarchy . variables class_hierarchy_... |
let attribute_from_attributes attributes = let attribute annotation ~ assumptions ~ name = let find attribute = String . equal ( Annotated . Attribute . name attribute ) name in attributes annotation ~ assumptions >>= List . find ~ f : find in attribute |
let less_or_equal ( ? attributes = fun _ ~ assumptions : _ -> None ) ( ? is_protocol = fun _ ~ protocol_assumptions : _ -> false ) handler = always_less_or_equal { ConstraintsSet . class_hierarchy = hierarchy handler ; all_attributes = attributes ; attribute = attribute_from_attributes attributes ; is_protocol ; assump... |
let is_compatible_with handler = is_compatible_with { ConstraintsSet . class_hierarchy = hierarchy handler ; all_attributes = ( fun _ ~ assumptions : _ -> None ) ; attribute = ( fun _ ~ assumptions : _ ~ name : _ -> None ) ; is_protocol = ( fun _ ~ protocol_assumptions : _ -> false ) ; assumptions = { protocol_assumpti... |
let join ( ? attributes = fun _ ~ assumptions : _ -> None ) handler = join { ConstraintsSet . class_hierarchy = hierarchy handler ; all_attributes = attributes ; attribute = attribute_from_attributes attributes ; is_protocol = ( fun _ ~ protocol_assumptions : _ -> false ) ; assumptions = { protocol_assumptions = Protoc... |
let meet handler = meet { ConstraintsSet . class_hierarchy = hierarchy handler ; all_attributes = ( fun _ ~ assumptions : _ -> None ) ; attribute = ( fun _ ~ assumptions : _ ~ name : _ -> None ) ; is_protocol = ( fun _ ~ protocol_assumptions : _ -> false ) ; assumptions = { protocol_assumptions = ProtocolAssumptions . ... |
let order = let bottom = " bottom " in let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order bottom ; insert order " 0 " ; insert order " 1 " ; insert order " 2 " ; insert order " 3 " ; insert order " 4 " ; insert order " 5 " ; connect order ~ predecessor " : 0 " ~ suc... |
let disconnected_order = let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order " A " ; insert order " B " ; handler order |
let variance_order = let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order " object " ; insert order " bool " ; insert order " str " ; insert order " int " ; insert order " float " ; connect order ~ predecessor " : int " ~ successor " : float " ; insert order " typing ... |
let multiplane_variance_order = let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order " str " ; insert order " int " ; insert order " float " ; insert order " object " ; insert order " bool " ; connect order ~ predecessor " : int " ~ successor " : float " ; insert orde... |
let parallel_planes_variance_order = let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order " str " ; insert order " int " ; insert order " float " ; insert order " object " ; connect order ~ predecessor " : int " ~ successor " : float " ; insert order " typing . Generi... |
let default = let order = MockClassHierarchyHandler . create ( ) in let open MockClassHierarchyHandler in insert order " typing . Generic " ; insert order " int " ; insert order " str " ; insert order " bytes " ; insert order " bool " ; insert order " float " ; insert order " object " ; connect order ~ predecessor " : ... |
let ( !! ) name = Type . Primitive name |
let test_less_or_equal context = assert_true ( less_or_equal order ~ left : Type . Bottom ~ right : Type . Top ) ; assert_false ( less_or_equal order ~ left : Type . Top ~ right : Type . Bottom ) ; assert_true ( less_or_equal order ~ left " :!! 0 " ~ right " :!! 0 " ) ; assert_true ( less_or_equal order ~ left : Type .... |
let test_is_compatible_with _ = let assert_is_compatible ( ? order = default ) left right = assert_true ( is_compatible_with order ~ left ~ right ) in let assert_not_compatible ( ? order = default ) left right = assert_false ( is_compatible_with order ~ left ~ right ) in let list_of_integer = Type . list Type . integer... |
let test_less_or_equal_variance _ = let assert_strict_less ~ order ~ right ~ left = assert_equal ~ printer ( : fun pair -> Format . sprintf " % B , % B " ( fst pair ) ( snd pair ) ) ( true , false ) ( less_or_equal order ~ left ~ right , less_or_equal order ~ left : right ~ right : left ) in assert_false ( less_or_equa... |
let test_join context = let assert_join ( ? order = default ) ( ? aliases = Type . empty_aliases ) left right expected = let parse_annotation = function | " $ bottom " -> Type . Bottom | _ as source -> parse_single_expression source |> Type . create ~ aliases in let attributes annotation ~ assumptions : _ = let parse_a... |
let test_meet _ = let assert_meet ( ? order = default ) ( ? aliases = Type . empty_aliases ) left right expected = let parse_annotation = function | " $ bottom " -> Type . Bottom | _ as source -> parse_single_expression source |> Type . create ~ aliases in assert_type_equal ( parse_annotation expected ) ( meet order ( ... |
let test_meet_callable _ = let assert_meet ( ? order = default ) left right expected = assert_type_equal expected ( meet order left right ) in let named_int_to_int = Type . Callable . create ~ name ( : Reference . create " name " ) ~ parameters : ( Defined [ Type . Callable . Parameter . Named { name = " a " ; annotati... |
let ( ) = " order " >::: [ " join " >:: test_join ; " less_or_equal " >:: test_less_or_equal ; " less_or_equal_variance " >:: test_less_or_equal_variance ; " is_compatible_with " >:: test_is_compatible_with ; " meet " >:: test_meet ; " meet_callable " >:: test_meet_callable ; ] |> Test . run |
type location = | Parameter of int list | Field of string | Nowhere |
module StringMap = Map . Make ( String ) String |
type t = location StringMap . t |
let make l = List . fold_left ( fun acc ( id , _ ) _ -> if StringMap . mem id acc then acc else StringMap . add id ( Field ( " w " ^ id ) id ) id acc ) acc StringMap . empty l |
let size t = StringMap . cardinal t |
let mem k t = StringMap . mem k t |
let find k t = StringMap . find k t |
let add k v t = if not ( StringMap . mem k t ) t then StringMap . add k v t else t |
let iter f t = StringMap . iter f t |
let fold f t z = StringMap . fold f t z |
let add_parameter t s l = t := add s ( Parameter l ) l ! t |
let add_field t s f = t := add s ( Field f ) f ! t |
let add_nowhere t s = t := add s Nowhere ! t |
let rec type_desc ~ mode ( ? bracket = false ) fmt = function | Tvar None -> fprintf fmt " _ " | Tvar ( Some name ) -> fprintf fmt " ' % s " name | Ttuple typs -> fprintf fmt " [ @< 1 >% a ] " @ tuple typs | Tarrow ( typ1 , typ2 , implicitness , label ) -> if bracket then fprintf fmt " ( [ " @ ; ( match implicitness wi... |
let field_decl fmt decl = fprintf fmt " % a :@ [ @< hv >% a ] " @ Ident . pprint decl . fld_ident type_expr decl . fld_type |
let ctor_args fmt = function | Ctor_tuple [ ] -> ( ) | Ctor_tuple typs -> tuple fmt typs | Ctor_record { tdec_desc = TRecord fields ; _ } -> fprintf fmt " { [ @< 2 >% a ] } " @ ( pp_print_list ~ pp_sep : comma_sep field_decl ) fields | Ctor_record _ -> assert false |
let ctor_decl fmt decl = fprintf fmt " % a % a " Ident . pprint decl . ctor_ident ctor_args decl . ctor_args ; match decl . ctor_ret with | Some typ -> fprintf fmt " @ :@ [ @< hv >% a ] " @ type_expr typ | None -> ( ) |
let type_decl_desc fmt = function | TAbstract -> ( ) | TAlias typ -> fprintf fmt " @ =@ [ @< hv >% a ] " @ type_expr typ | TRecord fields -> fprintf fmt " @ =@ { [ @< hv2 >% a ] } " @ ( pp_print_list ~ pp_sep : comma_sep field_decl ) fields | TVariant ctors -> fprintf fmt " @ =@ % a " ( pp_print_list ~ pp_sep : bar_sep... |
let type_decl ident fmt decl = fprintf fmt " type % a " Ident . pprint ident ; ( match decl . tdec_params with [ ] -> ( ) | _ -> tuple fmt decl . tdec_params ) ; type_decl_desc fmt decl . tdec_desc |
let rec basic_check l current_type expected_type loc = if expected_type <> current_type && not ( is_unknown current_type ) then ( assert ( not debug ) ; raise ( TypeError ( expected_type , current_type , loc ) ) ) ; List . iter ( fun e -> typer e expected_type ) l if body . t <> t && not ( is_unknown body . t ) then ( ... |
let test_assert_is_none context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import unittest class FakeTest ( unittest . TestCase ) : def foo ( self ) -> None : self . assertIsNotNone ( 2 ) } | [ ] ; assert_type_errors { | import typing import unittest class A : def __init__ ( self ... |
let test_assert_is context = assert_type_errors ~ context { | from typing import Type class Foo : x : int = 1 def foo ( o : Type [ object ] ) -> None : if ( o is Foo ) : o . x } | [ ] ; ( ) |
let test_check_global_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing class A : def __init__ ( self , x : typing . Optional [ int ] ) -> None : self . x = x def call ( ) -> None : pass def foo ( ) -> None : a = A ( 3 ) if a . x : reveal_type ( a . x ) i... |
let test_check_local_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . Optional [ int ] ) -> None : if x : reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` typing . Optional [ int ] ` ( inferred : ` int... |
let test_check_if_else_clause context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . Optional [ int ] ) -> None : if x is None : reveal_type ( x ) else : reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` None ` . " ; " ... |
let test_assert_contains_none context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | import typing def foo ( x : typing . List [ typing . Optional [ int ] ] ) -> None : assert None not in x reveal_type ( x ) } | ... |
let test_check_callable context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Dict , Optional class CallableClass : def __call__ ( self , x : int ) -> str : return " A " def foo ( x : Dict [ int , Optional [ CallableClass ] ] ) -> None : ret = x [ 0 ] if callable (... |
let test_check_final_attribute_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Final , Optional class Boo : . . . class Baz : z : Final [ Optional [ Boo ] ] = None class Bar : y : Final [ Optional [ Baz ] ] = None class Foo : x : Final [ Optional [... |
let test_check_temporary_refinement context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | MY_GLOBAL = 1 . 0 def arbitrary_call ( ) -> None : pass def test ( ) -> None : reveal_type ( MY_GLOBAL ) global MY_GLOBAL MY_GLOBAL = 1 reveal_type ( MY_GLOBAL ) arbitrary_call ( ) reveal_type (... |
let ( ) = " refinement " >::: [ " check_assert_is_none " >:: test_assert_is_none ; " check_assert_is " >:: test_assert_is ; " check_global_refinement " >:: test_check_global_refinement ; " check_local_refinement " >:: test_check_local_refinement ; " check_if_else_clause " >:: test_check_if_else_clause ; " check_assert_... |
module type S = sig type t val typerep_of_t : t Typerep . t val typename_of_t : t Typename . t end |
module type S1 = sig type ' a t val typerep_of_t : ' a Typerep . t -> ' a t Typerep . t val typename_of_t : ' a Typename . t -> ' a t Typename . t end |
module type S2 = sig type ( ' a , ' b ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ( ' a , ' b ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ( ' a , ' b ) t Typename . t end |
module type S3 = sig type ( ' a , ' b , ' c ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ( ' a , ' b , ' c ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ' c Typename . t -> ( ' a , ' b , ' c ) t Typename . t end |
module type S4 = sig type ( ' a , ' b , ' c , ' d ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ' d Typerep . t -> ( ' a , ' b , ' c , ' d ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ' c Typename . t -> ' d Typename . t -> ( ' a , ' b , ' c , ' d ) t Typ... |
module type S5 = sig type ( ' a , ' b , ' c , ' d , ' e ) t val typerep_of_t : ' a Typerep . t -> ' b Typerep . t -> ' c Typerep . t -> ' d Typerep . t -> ' e Typerep . t -> ( ' a , ' b , ' c , ' d , ' e ) t Typerep . t val typename_of_t : ' a Typename . t -> ' b Typename . t -> ' c Typename . t -> ' d Typename . t -> ... |
let repr_of_poly_variant : [ > ] -> int = fun variant -> let obj = Obj . repr variant in if Obj . is_int obj then Obj . obj obj else ( let size = Obj . size obj in assert ( size = 2 ) ; let repr = Obj . field obj 0 in assert ( Obj . is_int repr ) ; Obj . obj repr ) ; ; |
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 ( ) = assert ( repr_of_poly_variant ` Latency_stats = hash_variant " Latency_stats " ) |
let ( ) = assert ( repr_of_poly_variant ` zero = hash_variant " zero " ) |
let double_array_value = Obj . magic 0 . |
let has_double_array_tag a = Obj . double_array_tag = Obj . tag ( Obj . repr a ) |
let ( ) = let module M = struct type double = { a : float ; b : float } type simple = { c : float ; d : int } let double = { a = double_array_value ; b = double_array_value } let simple = { c = double_array_value ; d = double_array_value } end in assert ( has_double_array_tag M . double ) ; assert ( not ( has_double_ar... |
type kind_of_global_ident = Value | Type | Constr | Label |
type kind_of_ident = | Current | Initial | Next | Multi | Derivative |
type error = | Evar_undefined of Zident . t | Emissing of Zident . t | Eglobal_undefined of kind_of_global_ident * Lident . t | Eglobal_already of kind_of_global_ident * string | Ealready of kind_of_ident * Zident . t | Ealready_with_different_kinds of kind_of_ident * kind_of_ident * Zident . t | Eis_a_value of Zident ... |
let error loc kind = raise ( Error ( loc , kind ) ) |
type warning = | Wpartial_matching of Zelus . pattern | Wunreachable_state of Zident . t | Wmatch_unused of Zelus . pattern | Wequation_does_not_define_a_name | Wreset_target_state of bool * bool |
let kind_of_global_ident k = match k with | Value -> " value " | Type -> " type " | Constr -> " constructor " | Label -> " label " |
let kind_of_ident k = match k with | Current -> " value " | Derivative -> " derivative " | Initial -> " initial value " | Multi -> " multi emitted value " | Next -> " next value " |
let kind_message kind = match kind with | Tstatic _ -> " static " | Tcont -> " continuous " | Tany -> " combinatorial " | Tdiscrete ( s ) -> if s then " discrete " else " stateless discrete " | Tproba -> " probabilistic " |
let message loc kind = begin match kind with | Evar_undefined ( name ) -> eprintf " [ @% aTyping error : The value identifier % s is unbound . . ] " @@ output_location loc ( Zident . source name ) | Emissing ( s ) -> eprintf " [ @% aType error : no equation is given for name % s . . ] " @@ output_location loc ( Zident ... |
let warning loc w = if not ! Zmisc . no_warning then match w with | Wpartial_matching ( p ) -> Format . eprintf " [ @% aType warning : this pattern - matching is not exhaustive . . ] " @@ Format . eprintf " [ @ Here is an example of a value that is not matched . :@% a . ] " @@ | Wunreachable_state ( s ) -> eprintf " [ ... |
let fresh_env ( ) = let initially_opened_module = if ! Clflags . nopervasives then None else Some " Stdlib " in Typemod . initial_env ~ loc ( : Location . in_file " command line " ) ~ safe_string ( : not ! Clflags . unsafe_string ) ~ initially_opened_module ~ open_implicit_modules ( : List . rev ! Clflags . open_module... |
module Rewrite_loc = struct let queue = ref [ ] let update l = if l <> none then match ! queue with | [ ] -> assert false | l ' :: ls -> queue := Location_aux . union l l ' :: ls let enter ( ) = queue := Location . none :: ! queue let leave l0 = match ! queue with | [ ] -> assert false | [ l ] -> queue := [ ] ; Locatio... |
let rewrite_loc t = Rewrite_loc . start ( ) ; let t = match t with | ` str str -> ` str ( Rewrite_loc . u_structure str ) | ` fake str -> ` fake ( Rewrite_loc . u_structure str ) | ` sg sg -> ` sg ( Rewrite_loc . u_signature sg ) in Rewrite_loc . exit ( ) ; t |
type value = QuotedList of value list | Symbol of string | Keyword of string | Variable of string | Number of int | Boolean of bool | String of string | Plus | Minus | Divide | Multiply | Modulo | LT | LTE | GT | GTE | EQ | NEQ | AND | OR | LParen | RParen | Quote | EOF |
type sexp = Atom of value | List of sexp list |
let boolean_of_string s = match s with | " # f " -> false | _ -> true |
let rec debug_string_of_value value = match value with | QuotedList values -> " ' ( " ( ^ String . concat " , " ( List . map ( fun value -> string_of_value value ) values ) ) " ) " ^ | Symbol s -> " Symbol ( " ^ s " ) " ^ | Variable s -> " Variable ( " ^ s " ) " ^ | Keyword kw -> " Keyword ( " ^ kw " ) " ^ | Number s -... |
let rec string_of_sexp sexpr = match sexpr with | Atom x -> " Atom ( " ( ^ string_of_value x ) " ) " ^ | List xs -> " List ( " ( ^ String . concat " " ( List . map string_of_sexp xs ) ) " ) " ^ |
type test = { snippet : string ; loc : Lexing . position ; exn : exn } |
let name_table ( defns : Unresolved . t list ) = List . map defns ~ f ( : fun ( def : _ Named . t ) -> ( def . name , def ) ) |> String . Map . of_list_reducei ~ f ( : fun name v1 v2 -> let open Unresolved in match ( v1 . Named . data , v2 . data ) with | Enum_anon _ , _ -> v1 | _ , Enum_anon _ -> v2 | _ , _ -> if v1 =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.