text
stringlengths
0
601k
let class_signature sub cs = { pcsig_self = sub . typ sub cs . csig_self ; pcsig_fields = List . map ( sub . class_type_field sub ) cs . csig_fields ; }
let class_type_field sub ctf = let loc = sub . location sub ctf . ctf_loc in let attrs = sub . attributes sub ctf . ctf_attributes in let desc = match ctf . ctf_desc with Tctf_inherit ct -> Pctf_inherit ( sub . class_type sub ct ) | Tctf_val ( s , mut , virt , ct ) -> Pctf_val ( mkloc s loc , mut , virt , sub . typ sub...
let core_type sub ct = let loc = sub . location sub ct . ctyp_loc in let attrs = sub . attributes sub ct . ctyp_attributes in let desc = match ct . ctyp_desc with Ttyp_any -> Ptyp_any | Ttyp_var s -> Ptyp_var s | Ttyp_arrow ( label , ct1 , ct2 ) -> Ptyp_arrow ( label , sub . typ sub ct1 , sub . typ sub ct2 ) | Ttyp_tup...
let class_structure sub cs = let rec remove_self = function | { pat_desc = Tpat_alias ( p , id , _s ) } when string_is_prefix " selfpat " - ( Ident . name id ) -> remove_self p | p -> p in { pcstr_self = sub . pat sub ( remove_self cs . cstr_self ) ; pcstr_fields = List . map ( sub . class_field sub ) cs . cstr_fields ...
let row_field sub { rf_loc ; rf_desc ; rf_attributes ; } = let loc = sub . location sub rf_loc in let attrs = sub . attributes sub rf_attributes in let desc = match rf_desc with | Ttag ( label , bool , list ) -> Rtag ( label , bool , List . map ( sub . typ sub ) list ) | Tinherit ct -> Rinherit ( sub . typ sub ct ) in ...
let object_field sub { of_loc ; of_desc ; of_attributes ; } = let loc = sub . location sub of_loc in let attrs = sub . attributes sub of_attributes in let desc = match of_desc with | OTtag ( label , ct ) -> Otag ( label , sub . typ sub ct ) | OTinherit ct -> Oinherit ( sub . typ sub ct ) in Of . mk ~ loc ~ attrs desc |...
let class_field sub cf = let loc = sub . location sub cf . cf_loc in let attrs = sub . attributes sub cf . cf_attributes in let desc = match cf . cf_desc with Tcf_inherit ( ovf , cl , super , _vals , _meths ) -> Pcf_inherit ( ovf , sub . class_expr sub cl , Option . map ( fun v -> mkloc v loc ) super ) | Tcf_constraint...
let location _sub l = l
let default_mapper = { attribute = attribute ; attributes = attributes ; binding_op = binding_op ; structure = structure ; structure_item = structure_item ; module_expr = module_expr ; signature = signature ; signature_item = signature_item ; module_type = module_type ; with_constraint = with_constraint ; class_declara...
let untype_structure ( ? mapper = default_mapper ) structure = mapper . structure mapper structure
let untype_signature ( ? mapper = default_mapper ) signature = mapper . signature mapper signature
type info = { line : int ; col : int }
type expr = Var of int * int | Abs of string * t | App of t * t
type ctx = ( string * binding ) list
let with_info t = { info = { line = 0 ; col = 0 } ; expr = t }
let rec is_bound : ctx -> string -> bool = fun ctx x -> match ctx with | [ ] -> false | ( y , _ ) :: rest -> if x = y then true else is_bound rest x
let rec fresh_name ctx x = if is_bound ctx x then fresh_name ctx ( x ^ " ' " ) else ( ( x , Name_bind ) :: ctx , x )
let rec index_to_name : ctx -> int -> string option = fun ctx n -> match ctx with | [ ] -> None | ( x , _ ) :: xs -> if n = 0 then Some x else index_to_name xs ( n - 1 )
let rec pp_term ctx { expr ; info } = match expr with | Abs ( name , term ) -> let ctx2 , name2 = fresh_name ctx name in Io . format " ( lambda ~ p . \ n \ t " [ name2 ] ; pp_term ctx term ; Io . format " ) " [ ] | App ( fn , arg ) -> Io . format " ( " [ ] ; pp_term ctx fn ; pp_term ctx arg ; Io . format " ) " [ ] | Va...
let sample ( ) = with_info ( Abs ( " sample " , with_info ( App ( with_info ( Abs ( " f " , with_info ( Var ( 0 , 0 ) ) ) ) , with_info ( Var ( 0 , 1 ) ) ) ) ) )
let rec longident_of_path = function | Path . Pident ident -> Longident . Lident ( Ident . name ident ) | Pdot ( path , _mode , name ) | Pocamldot ( path , _mode , name , _ ) -> Ldot ( longident_of_path path , name ) | Papply ( path1 , path2 ) -> Lapply ( longident_of_path path1 , longident_of_path path2 )
module Type0 = struct open Type0 let rec type_desc ~ mode ? loc = function | Tvar None -> Type . none ? loc ( ) | Tvar ( Some name ) -> Type . var ? loc name | Ttuple typs -> Type . tuple ? loc ( List . map ~ f ( : type_expr ? loc ) typs ) | Tarrow ( typ1 , typ2 , explicit , label ) -> Type . arrow ? loc ~ explicit ~ l...
let rec type_desc = function | Typedast . Ttyp_var name -> Parsetypes . Ptyp_var name | Ttyp_tuple typs -> Ptyp_tuple ( List . map ~ f : type_expr typs ) | Ttyp_arrow ( typ1 , typ2 , explicit , label ) -> Ptyp_arrow ( type_expr typ1 , type_expr typ2 , explicit , label ) | Ttyp_ctor var -> Ptyp_ctor ( variant var ) | Tt...
let field_decl { Typedast . fld_ident ; fld_type ; fld_loc ; fld_fld = _ } = { Parsetypes . fld_ident = map_loc ~ f : Ident . name fld_ident ; fld_type = type_expr fld_type ; fld_loc }
let ctor_args = function | Typedast . Tctor_tuple typs -> Parsetypes . Ctor_tuple ( List . map ~ f : type_expr typs ) | Tctor_record fld -> Ctor_record ( List . map ~ f : field_decl fld )
let ctor_decl { Typedast . ctor_ident ; ctor_args = args ; ctor_ret ; ctor_loc ; ctor_ctor = _ } = { Parsetypes . ctor_ident = map_loc ~ f : Ident . name ctor_ident ; ctor_args = ctor_args args ; ctor_ret = Option . map ~ f : type_expr ctor_ret ; ctor_loc }
let type_decl_desc = function | Typedast . Tdec_abstract -> Parsetypes . Pdec_abstract | Tdec_alias typ -> Pdec_alias ( type_expr typ ) | Tdec_record fields -> Pdec_record ( List . map ~ f : field_decl fields ) | Tdec_variant ctors -> Pdec_variant ( List . map ~ f : ctor_decl ctors ) | Tdec_open -> Pdec_open | Tdec_ext...
let type_decl { Typedast . tdec_ident ; tdec_params ; tdec_desc ; tdec_loc ; tdec_tdec = _ } = { Parsetypes . tdec_ident = map_loc ~ f : Ident . name tdec_ident ; tdec_params = List . map ~ f : type_expr tdec_params ; tdec_desc = type_decl_desc tdec_desc ; tdec_loc }
let rec pattern_desc = function | Typedast . Tpat_any -> Parsetypes . Ppat_any | Tpat_variable str -> Ppat_variable ( map_loc ~ f : Ident . name str ) | Tpat_constraint ( p , typ ) -> Ppat_constraint ( pattern p , type_expr typ ) | Tpat_tuple ps -> Ppat_tuple ( List . map ~ f : pattern ps ) | Tpat_or ( p1 , p2 ) -> Ppa...
let rec expression_desc = function | Typedast . Texp_apply ( e , args ) -> Parsetypes . Pexp_apply ( expression e , List . filter_map args ~ f ( : fun ( explicit , label , e ) -> match explicit with | Explicit -> Some ( label , expression e ) | Implicit -> None ) ) | Texp_variable name -> Pexp_variable ( map_loc ~ f : ...
let conv_type = function | Typedast . Ttconv_with ( mode , decl ) -> Parsetypes . Ptconv_with ( mode , type_decl decl ) | Ttconv_to typ -> Ptconv_to ( type_expr typ )
let rec signature_desc = function | Typedast . Tsig_value ( name , typ ) -> Parsetypes . Psig_value ( map_loc ~ f : Ident . name name , type_expr typ ) | Tsig_instance ( name , typ ) -> Psig_instance ( map_loc ~ f : Ident . name name , type_expr typ ) | Tsig_type decl -> Psig_type ( type_decl decl ) | Tsig_convtype ( d...
let rec statement_desc = function | Typedast . Tstmt_value ( p , e ) -> Parsetypes . Pstmt_value ( pattern p , expression e ) | Tstmt_instance ( name , e ) -> Pstmt_instance ( map_loc ~ f : Ident . name name , expression e ) | Tstmt_type decl -> Pstmt_type ( type_decl decl ) | Tstmt_convtype ( decl , tconv , convname ,...
let vds = ref [ ]
let references = Hashtbl . create 256
let unit fn = Filename . chop_extension ( Filename . basename fn )
let rec collect_export fn = function | Sig_value ( _ , { Types . val_loc ; _ } ) when not val_loc . Location . loc_ghost -> if unit fn = unit val_loc . Location . loc_start . Lexing . pos_fname then vds := val_loc :: ! vds | Sig_module ( _ , { Types . md_type = Mty_signature sg ; _ } , _ ) -> List . iter ( collect_expo...
let collect_references = object inherit Tast_iter . iter as super method ! expression = function | { exp_desc = Texp_ident ( _ , _ , { Types . val_loc ; _ } ) ; exp_loc } -> Hashtbl . add references val_loc exp_loc | e -> super # expression e end
let rec load_file fn = if Filename . check_suffix fn " . cmi " && Sys . file_exists ( Filename . chop_suffix fn " . cmi " ^ " . mli " ) then let open Cmi_format in List . iter ( collect_export fn ) ( read_cmi fn ) . cmi_sign else if Filename . check_suffix fn " . cmt " then let open Cmt_format in match read fn with | (...
let report loc = if not ( Hashtbl . mem references loc ) then Format . printf " % a : unused exported value . " @ Location . print_loc loc
let ( ) = try for i = 1 to Array . length Sys . argv - 1 do load_file Sys . argv . ( i ) done ; List . iter report ! vds with exn -> Location . report_exception Format . err_formatter exn ; exit 2
module Unused : sig type unused = int end ; ; ^^^^^^^^^^^^^^^^^
module Unused : sig end } ] |
module Unused_nonrec : sig type nonrec used = int type nonrec unused = used end ; ; ^^^^^^^^^^^^^^^^^^^^^^^^^
module Unused_nonrec : sig end } ] |
module Unused_rec : sig type unused = A of unused end ; ; ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
module Unused_rec : sig end } ] |
module Used_constructor : sig type t val t : t type t = T let t = T end ; ;
module Used_constructor : sig type t val t : t end } ] |
module Unused_constructor : sig type t type t = T end ; ; ^
module Unused_constructor : sig type t end } ] |
module Unused_constructor_outside_patterns : sig type t val nothing : t -> unit type t = T let nothing = function | T -> ( ) end ; ; ^
module Unused_constructor_outside_patterns : sig type t val nothing : t -> unit end } ] |
module Unused_constructor_exported_private : sig type t = private T type t = T end ; ; ^
module Unused_constructor_exported_private : sig type t = private T end } ] |
module Used_private_constructor : sig type t val nothing : t -> unit type t = private T let nothing = function | T -> ( ) end ; ;
module Used_private_constructor : sig type t val nothing : t -> unit end } ] |
module Unused_private_constructor : sig type t type t = private T end ; ; ^
module Unused_private_constructor : sig type t end } ] |
module Exported_private_constructor : sig type t = private T type t = private T end ; ;
module Exported_private_constructor : sig type t = private T end } ] |
module Used_exception : sig val e : exn exception Somebody_uses_me let e = Somebody_uses_me end ; ;
module Used_exception : sig val e : exn end } ] |
module Used_extension_constructor : sig type t val t : t type t = . . type t += Somebody_uses_me let t = Somebody_uses_me end ; ;
module Used_extension_constructor : sig type t val t : t end } ] |
module Unused_exception : sig exception Nobody_uses_me end ; ; ^^^^^^^^^^^^^^^^^^^^^^^^
module Unused_exception : sig end } ] |
module Unused_extension_constructor : sig type t = . . type t = . . type t += Nobody_uses_me end ; ; ^^^^^^^^^^^^^^
module Unused_extension_constructor : sig type t = . . end } ] |
module Unused_exception_outside_patterns : sig val falsity : exn -> bool exception Nobody_constructs_me let falsity = function | Nobody_constructs_me -> true | _ -> false end ; ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
module Unused_exception_outside_patterns : sig val falsity : exn -> bool end } ] |
module Unused_extension_outside_patterns : sig type t = . . val falsity : t -> bool type t = . . type t += Noone_builds_me let falsity = function | Noone_builds_me -> true | _ -> false end ; ; ^^^^^^^^^^^^^^^
module Unused_extension_outside_patterns : sig type t = . . val falsity : t -> bool end } ] |
module Unused_exception_exported_private : sig type exn += private Private_exn exception Private_exn end ; ; ^^^^^^^^^^^^^^^^^^^^^
module Unused_exception_exported_private : sig type exn += private Private_exn end } ] |
module Unused_extension_exported_private : sig type t = . . type t += private Private_ext type t = . . type t += Private_ext end ; ; ^^^^^^^^^^^
module Unused_extension_exported_private : sig type t = . . type t += private Private_ext end } ] |
module Used_private_extension : sig type t val nothing : t -> unit type t = . . type t += private Private_ext let nothing = function | Private_ext | _ -> ( ) end ; ;
module Used_private_extension : sig type t val nothing : t -> unit end } ] |
module Unused_private_extension : sig type t type t = . . type t += private Private_ext end ; ; ^^^^^^^^^^^
module Unused_private_extension : sig type t end } ] |
module Exported_private_extension : sig type t = . . type t += private Private_ext type t = . . type t += private Private_ext end ; ;
module Exported_private_extension : sig type t = . . type t += private Private_ext end } ] |
module Pr7438 : sig module type S = sig type t = private [ > ` Foo ] end module type X = sig type t = private [ > ` Foo | ` Bar ] include S with type t := t end end ; ;
module Pr7438 : sig end } ] |
module Unused_type_disable_warning : sig type t = A [ @@ warning " - 34 " ] end ; ; ^
module Unused_type_disable_warning : sig end } ] |
module Unused_constructor_disable_warning : sig type t = A [ @@ warning " - 37 " ] end ; ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
module Unused_constructor_disable_warning : sig end } ] |
let silent v = String . length v > 0 && v . [ 0 ] = ' _ ' ; ;
let add_vars tbl ( vll1 , vll2 ) = let add_var ( v , _loc , used ) = Hashtbl . add tbl v used in List . iter add_var vll1 ; List . iter add_var vll2 ; ; ;
let rm_vars tbl ( vll1 , vll2 ) = let rm_var ( v , _ , _ ) = Hashtbl . remove tbl v in List . iter rm_var vll1 ; List . iter rm_var vll2 ; ; ;
let w_suspicious x = Warnings . Unused_var x ; ;
let w_strict x = Warnings . Unused_var_strict x ; ;
let check_rm_vars ppf tbl ( vlul_pat , vlul_as ) = let check_rm_var kind ( v , loc , used ) = if not ! used && not ( silent v ) then Location . print_warning loc ppf ( kind v ) ; Hashtbl . remove tbl v ; in List . iter ( check_rm_var w_strict ) vlul_pat ; List . iter ( check_rm_var w_suspicious ) vlul_as ; ; ;
let check_rm_let ppf tbl vlulpl = let check_rm_one flag ( v , loc , used ) = Hashtbl . remove tbl v ; flag && ( silent v || not ! used ) in let warn_var w_kind ( v , loc , used ) = if not ( silent v ) && not ! used then Location . print_warning loc ppf ( w_kind v ) in let check_rm_pat ( def , def_as ) = let def_unused ...
let rec get_vars ( ( vacc , asacc ) as acc ) p = match p . ppat_desc with | Ppat_any -> acc | Ppat_var v -> ( ( v , p . ppat_loc , ref false ) :: vacc , asacc ) | Ppat_alias ( pp , v ) -> get_vars ( vacc , ( ( v , p . ppat_loc , ref false ) :: asacc ) ) pp | Ppat_constant _ -> acc | Ppat_tuple pl -> List . fold_left ge...
let get_pel_vars pel = List . map ( fun ( p , _ ) -> get_vars ( [ ] , [ ] ) p ) pel ; ;
let rec structure ppf tbl l = List . iter ( structure_item ppf tbl ) l match s . pstr_desc with | Pstr_eval e -> expression ppf tbl e ; | Pstr_value ( recflag , pel ) -> let_pel ppf tbl recflag pel None ; | Pstr_primitive _ -> ( ) | Pstr_type _ -> ( ) | Pstr_exception _ -> ( ) | Pstr_exn_rebind _ -> ( ) | Pstr_module (...
let warn ppf ast = if Warnings . is_active ( w_suspicious " " ) || Warnings . is_active ( w_strict " " ) then begin let tbl = Hashtbl . create 97 in structure ppf tbl ast ; end ; ast ; ;