From 2bebd94553c267826635aa190213b2db6b3f9219 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Mon, 5 Sep 2016 13:36:26 -0700 Subject: [PATCH] Remove redundant Typ.struct_typ.csu field Summary: The Typ.struct_typ.csu field is now redundant with the Csu.t in the name: Typename.t field. Reviewed By: cristianoc Differential Revision: D3791861 fbshipit-source-id: 5370885 --- infer/src/IR/Typ.re | 24 +++++++++--------------- infer/src/IR/Typ.rei | 1 - infer/src/backend/localise.ml | 2 +- infer/src/backend/modelBuiltins.ml | 2 +- infer/src/backend/prover.ml | 15 ++++++++------- infer/src/backend/symExec.ml | 2 +- infer/src/backend/tabulation.ml | 5 +++-- infer/src/checkers/patternMatch.ml | 2 +- infer/src/clang/cField_decl.ml | 14 ++++++-------- infer/src/clang/cTrans.ml | 1 - infer/src/clang/cTypes_decl.ml | 4 ---- infer/src/clang/objcCategory_decl.ml | 16 +++++++--------- infer/src/clang/objcInterface_decl.ml | 13 ++++--------- infer/src/clang/objcProtocol_decl.ml | 6 ++---- infer/src/eradicate/eradicateChecks.ml | 2 +- infer/src/harness/androidFramework.ml | 2 +- infer/src/harness/harness.ml | 2 +- infer/src/harness/inhabit.ml | 2 +- infer/src/java/jTrans.ml | 2 +- infer/src/java/jTransType.ml | 4 +--- 20 files changed, 49 insertions(+), 72 deletions(-) diff --git a/infer/src/IR/Typ.re b/infer/src/IR/Typ.re index 2a0414bb9..4f78bd401 100644 --- a/infer/src/IR/Typ.re +++ b/infer/src/IR/Typ.re @@ -286,7 +286,6 @@ and struct_typ = { name: Typename.t, /** name */ instance_fields: struct_fields, /** non-static fields */ static_fields: struct_fields, /** static fields */ - csu: Csu.t, /** class/struct/union */ superclasses: list Typename.t, /** list of superclasses */ def_methods: list Procname.t, /** methods defined */ struct_annotations: item_annotation /** annotations */ @@ -306,9 +305,10 @@ let rec fld_typ_ann_compare fta1 fta2 => triple_compare Ident.fieldname_compare compare item_annotation_compare fta1 fta2 and fld_typ_ann_list_compare ftal1 ftal2 => IList.compare fld_typ_ann_compare ftal1 ftal2 and struct_typ_compare struct_typ1 struct_typ2 => - if (struct_typ1.csu == Csu.Class Csu.Java && struct_typ2.csu == Csu.Class Csu.Java) { + switch (struct_typ1.name, struct_typ2.name) { + | (TN_csu (Class Java) _, TN_csu (Class Java) _) => Typename.compare struct_typ1.name struct_typ2.name - } else { + | _ => let n = fld_typ_ann_list_compare struct_typ1.instance_fields struct_typ2.instance_fields; if (n != 0) { n @@ -317,12 +317,7 @@ and struct_typ_compare struct_typ1 struct_typ2 => if (n != 0) { n } else { - let n = Csu.compare struct_typ1.csu struct_typ2.csu; - if (n != 0) { - n - } else { - Typename.compare struct_typ1.name struct_typ2.name - } + Typename.compare struct_typ1.name struct_typ2.name } } } @@ -367,13 +362,12 @@ let struct_typ_equal struct_typ1 struct_typ2 => struct_typ_compare struct_typ1 s let equal t1 t2 => compare t1 t2 == 0; -let rec pp_struct_typ pe pp_base f {csu, instance_fields, name} => +let rec pp_struct_typ pe pp_base f {instance_fields, name} => if false { /* change false to true to print the details of struct */ F.fprintf f - "%s %a {%a} %a" - (Csu.name csu) + "%a {%a} %a" Typename.pp name (pp_seq (fun f (fld, t, _) => F.fprintf f "%a %a" (pp_full pe) t Ident.pp_fieldname fld)) @@ -534,8 +528,8 @@ let get_field_type_and_annotation fn => /** if [struct_typ] is a class, return its class kind (Java, CPP, or Obj-C) */ let struct_typ_get_class_kind struct_typ => - switch struct_typ.csu { - | Csu.Class class_kind => Some class_kind + switch struct_typ.name { + | TN_csu (Class class_kind) _ => Some class_kind | _ => None }; @@ -565,7 +559,7 @@ let struct_typ_is_objc_class struct_typ => let is_class_of_kind typ ck => switch typ { - | Tstruct {csu: Csu.Class ck'} => ck == ck' + | Tstruct {name: TN_csu (Class ck') _} => ck == ck' | _ => false }; diff --git a/infer/src/IR/Typ.rei b/infer/src/IR/Typ.rei index b387c0caf..b6f72ded4 100644 --- a/infer/src/IR/Typ.rei +++ b/infer/src/IR/Typ.rei @@ -141,7 +141,6 @@ and struct_typ = { name: Typename.t, /** name */ instance_fields: struct_fields, /** non-static fields */ static_fields: struct_fields, /** static fields */ - csu: Csu.t, /** class/struct/union */ superclasses: list Typename.t, /** list of superclasses */ def_methods: list Procname.t, /** methods defined */ struct_annotations: item_annotation /** annotations */ diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index 509ac8570..7492bf4b6 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -685,7 +685,7 @@ let desc_leak hpred_type_opt value_str_opt resource_opt resource_action_opt loc s, " to ", " on " in let typ_str = match hpred_type_opt with - | Some (Exp.Sizeof (Tstruct { csu = Class _; name; }, _, _)) -> + | Some (Exp.Sizeof (Tstruct { name = TN_csu (Class _, _) as name; }, _, _)) -> " of type " ^ Typename.name name ^ " " | _ -> " " in let desc_str = diff --git a/infer/src/backend/modelBuiltins.ml b/infer/src/backend/modelBuiltins.ml index 7da971ed6..e39c49ef1 100644 --- a/infer/src/backend/modelBuiltins.ml +++ b/infer/src/backend/modelBuiltins.ml @@ -760,7 +760,7 @@ let execute_alloc mk can_return_null evaluate_char_sizeof (Exp.Const (Const.Cint len)) | Exp.Sizeof _ -> e in let size_exp, procname = match args with - | [(Exp.Sizeof (Tstruct { csu = Class Objc; name } as s, len, subt), _)] -> + | [(Exp.Sizeof (Tstruct { name = TN_csu (Class Objc, _) as name } as s, len, subt), _)] -> let struct_type = match AttributesTable.get_correct_type_from_objc_class_name name with | Some struct_type -> struct_type diff --git a/infer/src/backend/prover.ml b/infer/src/backend/prover.ml index c076bb41f..5c90368f6 100644 --- a/infer/src/backend/prover.ml +++ b/infer/src/backend/prover.ml @@ -1476,7 +1476,6 @@ let expand_hpred_pointer calc_index_frame hpred : bool * bool * Sil.hpred = (Tstruct { instance_fields = [(fld, cnt_typ, Typ.item_annotation_empty)]; static_fields = []; - csu = Struct; name = TN_csu (Struct, Mangled.from_string "counterfeit"); superclasses = []; def_methods = []; @@ -1516,7 +1515,7 @@ struct let is_interface tenv class_name = match Tenv.lookup tenv class_name with - | Some ({ csu = Class Java } as struct_typ) -> + | Some ({ name = TN_csu (Class Java, _) } as struct_typ) -> (IList.length struct_typ.Typ.instance_fields = 0) && (IList.length struct_typ.Typ.def_methods = 0) | _ -> false @@ -1534,7 +1533,7 @@ struct let rec check cn = Typename.equal cn c2 || is_root_class c2 || match Tenv.lookup tenv cn with - | Some ({ csu = Class _; superclasses }) -> + | Some ({ name = TN_csu (Class _, _); superclasses }) -> IList.exists check superclasses | _ -> false in check c1 @@ -1555,7 +1554,8 @@ struct (** check if t1 is a subtype of t2, in Java *) let rec check_subtype_java tenv t1 t2 = match t1, t2 with - | Typ.Tstruct { csu = Class Java; name = cn1 }, Typ.Tstruct { csu = Class Java; name = cn2 } -> + | Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 }, + Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } -> check_subclass tenv cn1 cn2 | Typ.Tarray (dom_type1, _), Typ.Tarray (dom_type2, _) -> @@ -1564,7 +1564,7 @@ struct | Typ.Tptr (dom_type1, _), Typ.Tptr (dom_type2, _) -> check_subtype_java tenv dom_type1 dom_type2 - | Typ.Tarray _, Typ.Tstruct { Typ.csu = Csu.Class Csu.Java; name = cn2 } -> + | Typ.Tarray _, Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } -> Typename.equal cn2 serializable_type || Typename.equal cn2 cloneable_type || Typename.equal cn2 object_type @@ -1587,7 +1587,8 @@ struct let rec case_analysis_type_java tenv (t1, st1) (t2, st2) = match t1, t2 with - | Typ.Tstruct { csu = Class Java; name = cn1 }, Typ.Tstruct { csu = Class Java; name = cn2 } -> + | Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 }, + Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } -> Subtype.case_analysis (cn1, st1) (cn2, st2) (check_subclass tenv) (is_interface tenv) @@ -1597,7 +1598,7 @@ struct | Typ.Tptr (dom_type1, _), Typ.Tptr (dom_type2, _) -> case_analysis_type_java tenv (dom_type1, st1) (dom_type2, st2) - | Typ.Tstruct { Typ.csu = Csu.Class Csu.Java; name = cn1 }, Typ.Tarray _ -> + | Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 }, Typ.Tarray _ -> if (Typename.equal cn1 serializable_type || Typename.equal cn1 cloneable_type || Typename.equal cn1 object_type) && diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 05dbe962c..5b17ec424 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -506,7 +506,7 @@ let resolve_method tenv class_name proc_name = let right_proc_name = Procname.replace_class proc_name (Typename.name class_name) in match Tenv.lookup tenv class_name with - | Some { Typ.csu = Csu.Class _; def_methods; superclasses } -> + | Some { name = TN_csu (Class _, _); def_methods; superclasses } -> if method_exists right_proc_name def_methods then Some right_proc_name else diff --git a/infer/src/backend/tabulation.ml b/infer/src/backend/tabulation.ml index a57fa1287..8ff4594e9 100644 --- a/infer/src/backend/tabulation.ml +++ b/infer/src/backend/tabulation.ml @@ -467,8 +467,9 @@ let texp_star texp1 texp2 = | 0 -> ftal_sub ftal1' ftal2' | _ -> ftal_sub ftal1 ftal2' end in let typ_star t1 t2 = match t1, t2 with - | Typ.Tstruct { Typ.instance_fields = instance_fields1; csu = csu1 }, - Typ.Tstruct { Typ.instance_fields = instance_fields2; csu = csu2 } when csu1 = csu2 -> + | Typ.Tstruct { instance_fields = instance_fields1; name = TN_csu (csu1, _) }, + Typ.Tstruct { instance_fields = instance_fields2; name = TN_csu (csu2, _) } + when csu1 = csu2 -> if ftal_sub instance_fields1 instance_fields2 then t2 else t1 | _ -> t1 in match texp1, texp2 with diff --git a/infer/src/checkers/patternMatch.ml b/infer/src/checkers/patternMatch.ml index b16731bb3..8c4e1c7c6 100644 --- a/infer/src/checkers/patternMatch.ml +++ b/infer/src/checkers/patternMatch.ml @@ -35,7 +35,7 @@ let java_proc_name_with_class_method pn_java class_with_path method_name = with _ -> false) let get_direct_supers tenv = function - | { Typ.csu = Csu.Class _; superclasses } -> + | { Typ.name = TN_csu (Class _, _); superclasses } -> IList.map (Tenv.lookup tenv) superclasses |> IList.flatten_options | _ -> diff --git a/infer/src/clang/cField_decl.ml b/infer/src/clang/cField_decl.ml index 4d8158dc6..a0686b115 100644 --- a/infer/src/clang/cField_decl.ml +++ b/infer/src/clang/cField_decl.ml @@ -82,14 +82,12 @@ let add_missing_fields tenv class_name ck fields = match Tenv.lookup tenv class_tn_name with | Some ({ Typ.instance_fields } as struct_typ) -> let new_fields = General_utils.append_no_duplicates_fields instance_fields fields in - let class_type_info = - { - struct_typ with - Typ.instance_fields = new_fields; - static_fields = []; - csu = Csu.Class ck; - name = class_tn_name; - } in + let class_type_info = { + struct_typ with + instance_fields = new_fields; + static_fields = []; + name = class_tn_name; + } in Printing.log_out " Updating info for class '%s' in tenv\n" class_name; Tenv.add tenv class_tn_name class_type_info | _ -> () diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 9527ad6f1..dbeae72b9 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -130,7 +130,6 @@ struct { Typ.instance_fields = fields; static_fields = []; - csu = Csu.Class Csu.Objc; name = block_name; superclasses = []; def_methods = []; diff --git a/infer/src/clang/cTypes_decl.ml b/infer/src/clang/cTypes_decl.ml index 4945772c2..6eae48977 100644 --- a/infer/src/clang/cTypes_decl.ml +++ b/infer/src/clang/cTypes_decl.ml @@ -21,7 +21,6 @@ let add_predefined_objc_types tenv = { Typ.instance_fields = []; static_fields = []; - csu = Csu.Struct; name = TN_csu (Struct, Mangled.from_string CFrontend_config.objc_class); superclasses = []; def_methods = []; @@ -33,7 +32,6 @@ let add_predefined_objc_types tenv = { Typ.instance_fields = []; static_fields = []; - csu = Csu.Struct; name = TN_csu (Struct, Mangled.from_string CFrontend_config.objc_object); superclasses = []; def_methods = []; @@ -223,7 +221,6 @@ and get_record_declaration_struct_type tenv decl = let sil_type = Typ.Tstruct { Typ.instance_fields = non_static_fields; static_fields; - csu; name = sil_typename; superclasses; def_methods; @@ -246,7 +243,6 @@ and get_record_declaration_struct_type tenv decl = let empty_struct_type = Typ.Tstruct { Typ.instance_fields = extra_fields; static_fields = []; - csu; name = sil_typename; superclasses = []; def_methods = []; diff --git a/infer/src/clang/objcCategory_decl.ml b/infer/src/clang/objcCategory_decl.ml index 6ed795795..cfbddbc2b 100644 --- a/infer/src/clang/objcCategory_decl.ml +++ b/infer/src/clang/objcCategory_decl.ml @@ -81,15 +81,13 @@ let process_category type_ptr_to_sil_type tenv curr_class decl_info decl_list = | Some ({ Typ.instance_fields; def_methods } as struct_typ) -> let new_fields = General_utils.append_no_duplicates_fields fields instance_fields in let new_methods = General_utils.append_no_duplicates_methods methods def_methods in - let class_type_info = - { - struct_typ with - Typ.instance_fields = new_fields; - static_fields = []; - csu = Csu.Class Csu.Objc; - name = class_tn_name; - def_methods = new_methods; - } in + let class_type_info = { + struct_typ with + instance_fields = new_fields; + static_fields = []; + name = class_tn_name; + def_methods = new_methods; + } in Printing.log_out " Updating info for class '%s' in tenv\n" class_name; Tenv.add tenv class_tn_name class_type_info | _ -> ()); diff --git a/infer/src/clang/objcInterface_decl.ml b/infer/src/clang/objcInterface_decl.ml index 5d2ad2401..6ed249b99 100644 --- a/infer/src/clang/objcInterface_decl.ml +++ b/infer/src/clang/objcInterface_decl.ml @@ -128,15 +128,13 @@ let add_class_to_tenv type_ptr_to_sil_type tenv curr_class decl_info name_info d Printing.log_out "Class %s field:\n" class_name; IList.iter (fun (fn, _, _) -> Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) all_fields; - let interface_type_info = - { - Typ.instance_fields = all_fields; + let interface_type_info = Typ.{ + instance_fields = all_fields; static_fields = []; - csu = Csu.Class Csu.Objc; name = interface_name; superclasses; def_methods = methods; - struct_annotations = Typ.objc_class_annotation; + struct_annotations = objc_class_annotation; } in Tenv.add tenv interface_name interface_type_info; Printing.log_out @@ -153,10 +151,7 @@ let add_missing_methods tenv class_name ck decl_info decl_list curr_class = Ast_utils.update_sil_types_map decl_key (Typ.Tvar class_tn_name); begin match Tenv.lookup tenv class_tn_name with - | Some ({ Typ.static_fields = []; - csu = Csu.Class _; - def_methods; - } as struct_typ) -> + | Some ({ static_fields = []; name = TN_csu (Class _, _); def_methods; } as struct_typ) -> let methods = General_utils.append_no_duplicates_methods def_methods methods in let struct_typ' = { struct_typ with Typ.def_methods = methods; } in Tenv.add tenv class_tn_name struct_typ' diff --git a/infer/src/clang/objcProtocol_decl.ml b/infer/src/clang/objcProtocol_decl.ml index 4ed0442e5..8cfa8dbf3 100644 --- a/infer/src/clang/objcProtocol_decl.ml +++ b/infer/src/clang/objcProtocol_decl.ml @@ -33,11 +33,9 @@ let protocol_decl type_ptr_to_sil_type tenv decl = let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in Ast_utils.update_sil_types_map decl_key (Typ.Tvar protocol_name); let def_methods = ObjcProperty_decl.get_methods curr_class decl_list in - let protocol_type_info = - { - Typ.instance_fields = []; + let protocol_type_info = Typ.{ + instance_fields = []; static_fields = []; - csu = Csu.Protocol; name = protocol_name; superclasses = []; def_methods; diff --git a/infer/src/eradicate/eradicateChecks.ml b/infer/src/eradicate/eradicateChecks.ml index de8aee305..c5498a311 100644 --- a/infer/src/eradicate/eradicateChecks.ml +++ b/infer/src/eradicate/eradicateChecks.ml @@ -135,7 +135,7 @@ let check_condition case_zero find_canonical_duplicate curr_pname let loc = Cfg.Node.get_loc node in let throwable_found = ref false in let typ_is_throwable = function - | Typ.Tstruct { csu = Class _; name } -> + | Typ.Tstruct { name = TN_csu (Class _, _) as name } -> string_equal (Typename.name name) "java.lang.Throwable" | _ -> false in let do_instr = function diff --git a/infer/src/harness/androidFramework.ml b/infer/src/harness/androidFramework.ml index fb9e6758c..88b61ed8a 100644 --- a/infer/src/harness/androidFramework.ml +++ b/infer/src/harness/androidFramework.ml @@ -87,7 +87,7 @@ let is_android_lib_class class_name = a list of method names [lifecycle_procs_strs], get the appropriate typ and procnames *) let get_lifecycle_for_framework_typ_opt tenv lifecycle_typ lifecycle_proc_strs = match Tenv.lookup tenv (Typename.TN_csu (Csu.Class Csu.Java, lifecycle_typ)) with - | Some ({ Typ.csu = Csu.Class _; def_methods } as lifecycle_typ) -> + | Some ({ name = TN_csu (Class _, _); def_methods } as lifecycle_typ) -> (* TODO (t4645631): collect the procedures for which is_java is returning false *) let lookup_proc lifecycle_proc = IList.find (fun decl_proc -> diff --git a/infer/src/harness/harness.ml b/infer/src/harness/harness.ml index 97400612f..bd7d00187 100644 --- a/infer/src/harness/harness.ml +++ b/infer/src/harness/harness.ml @@ -18,7 +18,7 @@ module F = Format constituting a lifecycle trace *) let try_create_lifecycle_trace struct_typ lifecycle_struct_typ lifecycle_procs tenv = match struct_typ with - | { Typ.csu = Class Java; name } -> + | { Typ.name = TN_csu (Class Java, _) as name } -> if PatternMatch.is_subtype tenv struct_typ lifecycle_struct_typ && not (AndroidFramework.is_android_lib_class name) then let ptr_to_struct_typ = Some (Typ.Tptr (Tstruct struct_typ, Pk_pointer)) in diff --git a/infer/src/harness/inhabit.ml b/infer/src/harness/inhabit.ml index 7927b2032..58a9dc3c2 100644 --- a/infer/src/harness/inhabit.ml +++ b/infer/src/harness/inhabit.ml @@ -95,7 +95,7 @@ let rec inhabit_typ typ cfg env = (* select methods that are constructors and won't force us into infinite recursion because * we are already inhabiting one of their argument types *) let get_all_suitable_constructors typ = match typ with - | Typ.Tstruct { Typ.csu = Csu.Class _; def_methods } -> + | Typ.Tstruct { name = TN_csu (Class _, _); def_methods } -> let is_suitable_constructor p = let try_get_non_receiver_formals p = get_non_receiver_formals (formals_from_name cfg p) in diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 431899b39..5a4d59a8a 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -108,7 +108,7 @@ let retrieve_fieldname fieldname = let get_field_name program static tenv cn fs = match JTransType.get_class_type_no_pointer program tenv cn with - | Typ.Tstruct { Typ.instance_fields; static_fields; csu = Csu.Class _ } -> + | Typ.Tstruct { Typ.instance_fields; static_fields; name = TN_csu (Class _, _) } -> let fieldname, _, _ = try IList.find diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index c2a25363c..bca01ce11 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -88,7 +88,7 @@ let rec create_array_type typ dim = let extract_cn_no_obj typ = match typ with - | Typ.Tptr (Tstruct { csu = Class _; name }, Pk_pointer) -> + | Typ.Tptr (Tstruct { name = TN_csu (Class _, _) as name }, Pk_pointer) -> let class_name = Typename.name name in if class_name = JConfig.object_cl then None else @@ -238,7 +238,6 @@ let dummy_type cn = Typ.Tstruct { Typ.instance_fields = []; static_fields = []; - csu = Csu.Class Csu.Java; name = Typename.Java.from_string (JBasics.cn_name cn); superclasses = []; def_methods = []; @@ -339,7 +338,6 @@ and create_sil_type program tenv cn = Typ.Tstruct { Typ.instance_fields; static_fields; - csu = Csu.Class Csu.Java; name = Typename.Java.from_string (JBasics.cn_name cn); superclasses; def_methods;