From bb37447bd5f1750e5e5f980597f2bfe15be0c5c0 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Tue, 12 May 2020 02:40:44 -0700 Subject: [PATCH] [nullsafe] Log class hierarchy for file level analysis Summary: This will is useful for understanding and debugging file level analysis flow. Reviewed By: jvillard Differential Revision: D21449240 fbshipit-source-id: 7c259674b --- infer/src/nullsafe/AggregatedSummaries.ml | 21 +++++++++++++++++++++ infer/src/nullsafe/AggregatedSummaries.mli | 2 ++ infer/src/nullsafe/FileLevelAnalysis.ml | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/infer/src/nullsafe/AggregatedSummaries.ml b/infer/src/nullsafe/AggregatedSummaries.ml index c4c5e4d66..4974a6922 100644 --- a/infer/src/nullsafe/AggregatedSummaries.ml +++ b/infer/src/nullsafe/AggregatedSummaries.ml @@ -6,6 +6,7 @@ *) open! IStd +module F = Format module ClassInfo = struct type t = @@ -59,6 +60,26 @@ module ClassInfo = struct List.map t.nested_classes_info ~f:get_recursive_summaries |> List.concat in this_summaries @ nested_summaries @ anonymous_summaries + + + let rec pp fmt class_info = + let pp_anonymous fmt (class_name, summaries) = + F.fprintf fmt "Class name: %a, Summaries: %d" JavaClassName.pp class_name + (List.length summaries) + in + let pp_list fmt items ~pp = + if List.is_empty items then F.fprintf fmt "" + else List.iter items ~f:(F.fprintf fmt "%a@\n" pp) + in + let pp_content fmt {summaries; nested_anonymous_classes; nested_classes_info} = + F.fprintf fmt + "Summaries: %d@\nNested anonymous classes:@\n @[%a@]@\nNested classes:@\n @[%a@]" + (List.length summaries) (pp_list ~pp:pp_anonymous) + (JavaClassName.Map.bindings nested_anonymous_classes) + (pp_list ~pp) nested_classes_info + in + F.fprintf fmt "Class name: %a@\n @[%a@]" JavaClassName.pp class_info.class_name pp_content + class_info end (* If key (class_name) was not in the map yet, add it, otherwise modify the existing value. diff --git a/infer/src/nullsafe/AggregatedSummaries.mli b/infer/src/nullsafe/AggregatedSummaries.mli index 9bd4048d3..40fb7bbd5 100644 --- a/infer/src/nullsafe/AggregatedSummaries.mli +++ b/infer/src/nullsafe/AggregatedSummaries.mli @@ -27,6 +27,8 @@ module ClassInfo : sig val get_recursive_summaries : t -> (JavaClassName.t * NullsafeSummary.t) list (** A flattened list of all summaries, user-level, nested, and anonymous, combined together *) + + val pp : Format.formatter -> t -> unit end val aggregate : (JavaClassName.t * NullsafeSummary.t) list -> ClassInfo.t list diff --git a/infer/src/nullsafe/FileLevelAnalysis.ml b/infer/src/nullsafe/FileLevelAnalysis.ml index cd014dfb8..ff261e846 100644 --- a/infer/src/nullsafe/FileLevelAnalysis.ml +++ b/infer/src/nullsafe/FileLevelAnalysis.ml @@ -47,7 +47,15 @@ let analyze_top_level_class tenv source_file issue_log top_level_class_info = let analyze_file ({InterproceduralAnalysis.file_exe_env; source_file} as analysis_data) = + Logging.debug Analysis Medium "Starting file level analysis of %a@\n" SourceFile.pp source_file ; let all_summaries = get_summaries analysis_data in let tenv = Exe_env.load_java_global_tenv file_exe_env in let top_level_classes = AggregatedSummaries.aggregate all_summaries in - List.fold top_level_classes ~init:IssueLog.empty ~f:(analyze_top_level_class tenv source_file) + List.iter top_level_classes ~f:(fun top_level_class -> + Logging.debug Analysis Medium "Hierarchy for a top level class:@\n%a@\n" + AggregatedSummaries.ClassInfo.pp top_level_class ) ; + let issue_log = + List.fold top_level_classes ~init:IssueLog.empty ~f:(analyze_top_level_class tenv source_file) + in + Logging.debug Analysis Medium "Finished file level analysis of %a@\n" SourceFile.pp source_file ; + issue_log