text stringlengths 12 786k |
|---|
let univars = ref ( [ ] : ( string * type_expr ) list ) |
let pre_univars = ref ( [ ] : type_expr list ) |
let used_variables = ref ( TyVarMap . empty : ( type_expr * Location . t ) TyVarMap . t ) |
let reset_type_variables ( ) = reset_global_level ( ) ; Ctype . reset_reified_var_counter ( ) ; type_variables := TyVarMap . empty |
let narrow ( ) = ( increase_global_level ( ) , ! type_variables ) |
let widen ( gl , tv ) = restore_global_level gl ; type_variables := tv |
let strict_ident c = ( c = ' _ ' || c >= ' a ' && c <= ' z ' || c >= ' A ' && c <= ' Z ' ) |
let validate_name = function None -> None | Some name as s -> if name <> " " && strict_ident name . [ 0 ] then s else None |
let new_global_var ? name ( ) = new_global_var ? name ( : validate_name name ) ( ) |
let newvar ? name ( ) = newvar ? name ( : validate_name name ) ( ) |
let type_variable loc name = try TyVarMap . find name ! type_variables with Not_found -> raise ( Error ( loc , Env . empty , Unbound_type_variable ( " ' " ^ name ) ) ) |
let valid_tyvar_name name = name <> " " && name . [ 0 ] <> ' _ ' |
let transl_type_param env styp = let loc = styp . ptyp_loc in match styp . ptyp_desc with Ptyp_any -> let ty = new_global_var ~ name " : _ " ( ) in { ctyp_desc = Ttyp_any ; ctyp_type = ty ; ctyp_env = env ; ctyp_loc = loc ; ctyp_attributes = styp . ptyp_attributes ; } | Ptyp_var... |
let transl_type_param env styp = Builtin_attributes . warning_scope styp . ptyp_attributes ( fun ( ) -> transl_type_param env styp ) |
let new_pre_univar ? name ( ) = let v = newvar ? name ( ) in pre_univars := v :: ! pre_univars ; v |
type policy = Fixed | Extensible | Univars |
let rec transl_type env policy styp = Builtin_attributes . warning_scope styp . ptyp_attributes ( fun ( ) -> transl_type_aux env policy styp ) let loc = styp . ptyp_loc in let ctyp ctyp_desc ctyp_type = { ctyp_desc ; ctyp_type ; ctyp_env = env ; ctyp_loc = loc ; ctyp_attributes = styp . ... |
let rec make_fixed_univars ty = let ty = repr ty in if ty . level >= Btype . lowest_level then begin Btype . mark_type_node ty ; match ty . desc with | Tvariant row -> let row = Btype . row_repr row in let more = Btype . row_more row in if Btype . is_Tunivar more then ty . desc <- Tvariant { ... |
let make_fixed_univars ty = make_fixed_univars ty ; Btype . unmark_type ty |
let create_package_mty = create_package_mty false |
let globalize_used_variables env fixed = let r = ref [ ] in TyVarMap . iter ( fun name ( ty , loc ) -> let v = new_global_var ( ) in let snap = Btype . snapshot ( ) in if try unify env v ty ; true with _ -> Btype . backtrack snap ; false then try r := ( loc , v , TyVarMap . ... |
let transl_simple_type env fixed styp = univars := [ ] ; used_variables := TyVarMap . empty ; let typ = transl_type env ( if fixed then Fixed else Extensible ) styp in globalize_used_variables env fixed ( ) ; make_fixed_univars typ . ctyp_type ; typ |
let transl_simple_type_univars env styp = univars := [ ] ; used_variables := TyVarMap . empty ; pre_univars := [ ] ; begin_def ( ) ; let typ = transl_type env Univars styp in let new_variables = ! used_variables in used_variables := TyVarMap . empty ; TyVarMap . iter ( fun name p ... |
let transl_simple_type_delayed env styp = univars := [ ] ; used_variables := TyVarMap . empty ; let typ = transl_type env Extensible styp in make_fixed_univars typ . ctyp_type ; ( typ , globalize_used_variables env false ) |
let transl_type_scheme env styp = reset_type_variables ( ) ; begin_def ( ) ; let typ = transl_simple_type env false styp in end_def ( ) ; generalize typ . ctyp_type ; typ |
let report_error env ppf = function | Unbound_type_variable name -> let add_name name _ l = if name = " _ " then l else ( " ' " ^ name ) :: l in let names = TyVarMap . fold add_name ! type_variables [ ] in fprintf ppf " The type variable % s is unbound in this type declaration . @ ... |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , env , err ) -> Some ( Location . error_of_printer ~ loc ( report_error env ) err ) | Error_forward err -> Some err | _ -> None ) |
let test_check_bounded_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeVar , Callable TFun = TypeVar ( " TFun " , bound = Callable [ [ int ] , None ] ) def foo ( x : TFun ) -> None : x ( 7 ) } | [ ]... |
let test_check_unbounded_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing T = typing . TypeVar ( ' T ' ) def expects_any ( input : object ) -> None : . . . def expects_string ( inut : str ) -> None : . . . def fo... |
let test_check_variable_bindings context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import str_to_int import typing T = typing . TypeVar ( ' T ' , bound = int ) def foo ( t : T ) -> None : str_to_int ( t ) } | [ " Incompatible pa... |
let test_unbound_variables context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | def foo ( ) -> None : x = [ ] } | [ " Incomplete type [ 37 ] : Type ` typing . List [ Variab... |
let test_distinguish context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing _T1 = typing . TypeVar ( " _T1 " ) _T2 = typing . TypeVar ( " _T2 " ) class C ( typing . Generic [ _T1 ] ) : def pair ( self , a : _T1 , b : _... |
let test_integer_variables context = assert_type_errors ~ context { | import typing_extensions T = typing_extensions . IntVar ( " T " ) X = typing_extensions . IntVar ( " X " ) def baz ( x : X ) -> X : return x def bop ( x : int ) -> None : pass def foo ( x : T ) -> T : y... |
let test_nested_variable_error context = assert_type_errors ~ context { | import typing T1 = typing . TypeVar ( " T1 " ) T2 = typing . TypeVar ( " T2 " , typing . List [ T1 ] , typing . Dict [ str , T1 ] ) } | [ " Invalid type [ 31 ] : Expression ` Variable [ ... |
let test_single_explicit_error context = assert_type_errors ~ context { | import typing T1 = typing . TypeVar ( " T1 " , int ) } | [ " Invalid type [ 31 ] : TypeVar can ' t have a single explicit constraint . Did you mean ` bound = int ` " ; ? ] ; ( ) |
let test_callable_parameter_variadics context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , List import pyre_extensions V = pyre_extensions . ParameterSpecification ( " V " ) def f ( x : Callable [ V , int ] ) -> Callable [... |
let test_user_defined_parameter_specification_classes context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , ParamSpec TParams = ParamSpec ( " TParams " ) def client ( f : Callable [ TParams , int ] ) -> None : def inner ( ... |
let test_duplicate_type_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeVar , Generic T = TypeVar ( " T " ) S = TypeVar ( " S " ) class A ( Generic [ T , S , T ] ) : pass } | [ " Duplicate type varia... |
let test_generic_aliases context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import List MyList = List [ int ] x : MyList reveal_type ( x ) reveal_type ( x [ 0 ] ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` ... |
let test_recursive_aliases context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple , Union Tree = Union [ int , Tuple [ " Tree " , " Tree " ] ] x : Tree reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed t... |
let test_variadic_tuples context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) def foo ( x : Tuple [ int , Unpack [ Ts ] ] ) -> Tuple [ bool , ... |
let test_variadic_classes context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Generic from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) class Tensor ( Generic [ Unpack [ Ts ] ] ) : . . . def add_boo... |
let test_variadic_callables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , Tuple from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) def make_tuple ( leave_this_out : int , * args : Unpack [ T... |
let ( ) = " typeVariable " >::: [ " check_bounded_variables " >:: test_check_bounded_variables ; " check_unbounded_variables " >:: test_check_unbounded_variables ; " check_variable_bindings " >:: test_check_variable_bindings ; " unbound_variables " >:: test_unbound_variables ; " ... |
module Make0 ( X : Named_intf . S0 ) : Typerepable . S with type t := X . t = struct module M = Make_typename . Make0 ( X ) let typerep_of_t = Typerep . Named ( M . named , None ) let typename_of_t = M . typename_of_t end |
module Make1 ( X : Named_intf . S1 ) : Typerepable . S1 with type ' a t := ' a X . t = struct module M = Make_typename . Make1 ( X ) let typerep_of_t of_p1 = Typerep . Named ( M . named of_p1 , None ) let typename_of_t = M . typename_of_t end |
module Make2 ( X : Named_intf . S2 ) : Typerepable . S2 with type ( ' a , ' b ) t := ( ' a , ' b ) X . t = struct module M = Make_typename . Make2 ( X ) let typerep_of_t of_p1 of_p2 = Typerep . Named ( M . named of_p1 of_p2 , None ) let typename_of_t = M . typename... |
module Make3 ( X : Named_intf . S3 ) : Typerepable . S3 with type ( ' a , ' b , ' c ) t := ( ' a , ' b , ' c ) X . t = struct module M = Make_typename . Make3 ( X ) let typerep_of_t of_p1 of_p2 of_p3 = Typerep . Named ( M . named of_p1 of_p2 of_p3 , None ) let... |
module Make4 ( X : Named_intf . S4 ) : Typerepable . S4 with type ( ' a , ' b , ' c , ' d ) t := ( ' a , ' b , ' c , ' d ) X . t = struct module M = Make_typename . Make4 ( X ) let typerep_of_t of_p1 of_p2 of_p3 of_p4 = Typerep . Named ( M . named of_p1 of... |
module Make5 ( X : Named_intf . S5 ) : Typerepable . S5 with type ( ' a , ' b , ' c , ' d , ' e ) t := ( ' a , ' b , ' c , ' d , ' e ) X . t = struct module M = Make_typename . Make5 ( X ) let typerep_of_t of_p1 of_p2 of_p3 of_p4 of_p5 = Typerep . Name... |
type ' a writer = { size : ' a Size . sizer ; write : ' a Write . writer } |
type ' a reader = { read : ' a Read . reader ; vtag_read : ( int -> ' a ) Read . reader } |
type ' a t = { shape : Shape . t ; writer : ' a writer ; reader : ' a reader } |
type ' a writer0 = ' a writer |
type ' a reader0 = ' a reader |
type ' a t0 = ' a t |
module S1 = struct type ( ' a , ' b ) writer = ' a writer0 -> ' b writer0 type ( ' a , ' b ) reader = ' a reader0 -> ' b reader0 type ( ' a , ' b ) t = ' a t0 -> ' b t0 end |
module S2 = struct type ( ' a , ' b , ' c ) writer = ' a writer0 -> ( ' b , ' c ) S1 . writer type ( ' a , ' b , ' c ) reader = ' a reader0 -> ( ' b , ' c ) S1 . reader type ( ' a , ' b , ' c ) t = ' a t0 -> ( ' b , ' c ) S1 . t ... |
module S3 = struct type ( ' a , ' b , ' c , ' d ) writer = ' a writer0 -> ( ' b , ' c , ' d ) S2 . writer type ( ' a , ' b , ' c , ' d ) reader = ' a reader0 -> ( ' b , ' c , ' d ) S2 . reader type ( ' a , ' b , ' c , ' d ) t... |
let variant_wrong_type name _buf ~ pos_ref _x = Common . raise_variant_wrong_type name ! pos_ref ; ; |
let bin_writer_unit = { size = Size . bin_size_unit ; write = Write . bin_write_unit } |
let bin_reader_unit = { read = Read . bin_read_unit ; vtag_read = variant_wrong_type " unit " } ; ; |
let bin_unit = { shape = bin_shape_unit ; writer = bin_writer_unit ; reader = bin_reader_unit } ; ; |
let bin_writer_bool = { size = Size . bin_size_bool ; write = Write . bin_write_bool } |
let bin_reader_bool = { read = Read . bin_read_bool ; vtag_read = variant_wrong_type " bool " } ; ; |
let bin_bool = { shape = bin_shape_bool ; writer = bin_writer_bool ; reader = bin_reader_bool } ; ; |
let bin_writer_string = { size = Size . bin_size_string ; write = Write . bin_write_string } |
let bin_reader_string = { read = Read . bin_read_string ; vtag_read = variant_wrong_type " string " } ; ; |
let bin_string = { shape = bin_shape_string ; writer = bin_writer_string ; reader = bin_reader_string } ; ; |
let bin_writer_bytes = { size = Size . bin_size_bytes ; write = Write . bin_write_bytes } |
let bin_reader_bytes = { read = Read . bin_read_bytes ; vtag_read = variant_wrong_type " bytes " } ; ; |
let bin_bytes = { shape = bin_shape_bytes ; writer = bin_writer_bytes ; reader = bin_reader_bytes } ; ; |
let bin_writer_char = { size = Size . bin_size_char ; write = Write . bin_write_char } |
let bin_reader_char = { read = Read . bin_read_char ; vtag_read = variant_wrong_type " char " } ; ; |
let bin_char = { shape = bin_shape_char ; writer = bin_writer_char ; reader = bin_reader_char } ; ; |
let bin_writer_int = { size = Size . bin_size_int ; write = Write . bin_write_int } |
let bin_reader_int = { read = Read . bin_read_int ; vtag_read = variant_wrong_type " int " } |
let bin_int = { shape = bin_shape_int ; writer = bin_writer_int ; reader = bin_reader_int } |
let bin_writer_float = { size = Size . bin_size_float ; write = Write . bin_write_float } |
let bin_reader_float = { read = Read . bin_read_float ; vtag_read = variant_wrong_type " float " } ; ; |
let bin_float = { shape = bin_shape_float ; writer = bin_writer_float ; reader = bin_reader_float } ; ; |
let bin_writer_int32 = { size = Size . bin_size_int32 ; write = Write . bin_write_int32 } |
let bin_reader_int32 = { read = Read . bin_read_int32 ; vtag_read = variant_wrong_type " int32 " } ; ; |
let bin_int32 = { shape = bin_shape_int32 ; writer = bin_writer_int32 ; reader = bin_reader_int32 } ; ; |
let bin_writer_int64 = { size = Size . bin_size_int64 ; write = Write . bin_write_int64 } |
let bin_reader_int64 = { read = Read . bin_read_int64 ; vtag_read = variant_wrong_type " int64 " } ; ; |
let bin_int64 = { shape = bin_shape_int64 ; writer = bin_writer_int64 ; reader = bin_reader_int64 } ; ; |
let bin_writer_nativeint = { size = Size . bin_size_nativeint ; write = Write . bin_write_nativeint } ; ; |
let bin_reader_nativeint = { read = Read . bin_read_nativeint ; vtag_read = variant_wrong_type " nativeint " } ; ; |
let bin_nativeint = { shape = bin_shape_nativeint ; writer = bin_writer_nativeint ; reader = bin_reader_nativeint } ; ; |
let bin_writer_nat0 = { size = Size . bin_size_nat0 ; write = Write . bin_write_nat0 } |
let bin_reader_nat0 = { read = Read . bin_read_nat0 ; vtag_read = variant_wrong_type " nat0 " } ; ; |
let bin_nat0 = { shape = bin_shape_nat0 ; writer = bin_writer_nat0 ; reader = bin_reader_nat0 } ; ; |
let bin_writer_ref bin_writer_el = { size = ( fun v -> Size . bin_size_ref bin_writer_el . size v ) ; write = ( fun buf ~ pos v -> Write . bin_write_ref bin_writer_el . write buf ~ pos v ) } ; ; |
let bin_reader_ref bin_reader_el = { read = ( fun buf ~ pos_ref -> Read . bin_read_ref bin_reader_el . read buf ~ pos_ref ) ; vtag_read = variant_wrong_type " ref " } ; ; |
let bin_shape_ref x1 = Shape . bin_shape_ref x1 |
let bin_ref bin_el = { shape = bin_shape_ref bin_el . shape ; writer = bin_writer_ref bin_el . writer ; reader = bin_reader_ref bin_el . reader } ; ; |
let bin_writer_lazy bin_writer_el = { size = ( fun v -> Size . bin_size_lazy bin_writer_el . size v ) ; write = ( fun buf ~ pos v -> Write . bin_write_lazy bin_writer_el . write buf ~ pos v ) } ; ; |
let bin_reader_lazy bin_reader_el = { read = ( fun buf ~ pos_ref -> Read . bin_read_lazy bin_reader_el . read buf ~ pos_ref ) ; vtag_read = variant_wrong_type " lazy " } ; ; |
let bin_shape_lazy x1 = Shape . bin_shape_lazy x1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.