From 5691f240905f60c272435f5d5f2d9338e36ec0b5 Mon Sep 17 00:00:00 2001 From: jrm Date: Thu, 12 Nov 2015 15:22:32 -0800 Subject: [PATCH] Use the summaries to store the @CallsExpensive attributes Summary: public Load and store the inferred attributes on the analysis summaries. The next step is to use the call stack from performance critical methods to expensive methods form the summary payload instead of modifying the attributes. Reviewed By: sblackshear, cristianoc Differential Revision: D2644530 fb-gh-sync-id: b99a8e3 --- infer/src/checkers/performanceCritical.ml | 31 +++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/infer/src/checkers/performanceCritical.ml b/infer/src/checkers/performanceCritical.ml index 8249d5bb9..3eabc70c8 100644 --- a/infer/src/checkers/performanceCritical.ml +++ b/infer/src/checkers/performanceCritical.ml @@ -19,6 +19,7 @@ let expensive_overrides_unexpensive = let unannotated_overrides_performance_critical = "CHECKERS_UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL" + let search_expensive_call checked_pnames expensive_callee (pname, _) = match expensive_callee with | Some callee_pname -> Some callee_pname @@ -27,9 +28,10 @@ let search_expensive_call checked_pnames expensive_callee (pname, _) = else begin checked_pnames := Procname.Set.add pname !checked_pnames; - match AttributesTable.load_attributes pname with + match Specs.get_summary pname with | None -> None - | Some attributes -> + | Some summary -> + let attributes = Specs.get_attributes summary in let annotated_signature = Annotations.get_annotated_signature attributes in let ret_annotation, _ = annotated_signature.Annotations.ret in if Annotations.ia_calls_expensive ret_annotation then @@ -67,6 +69,23 @@ let method_is_expensive pname = check_method Annotations.ia_is_expensive pname +let update_summary_attributes pname = + match Specs.get_summary pname with + | None -> + let pname_str = Procname.to_string pname in + failwith ("The summary should have been created before running the checker on "^pname_str) + | Some summary -> + let attributes = Specs.get_attributes summary in + let ret_annot, param_annot = attributes.ProcAttributes.method_annotation in + let updated_method_annot = + (Annotations.calls_expensive_annotation, true) :: ret_annot, param_annot in + let updated_attributes = + { attributes with ProcAttributes.method_annotation = updated_method_annot } in + let updated_summary = + { summary with Specs.attributes = updated_attributes } in + Specs.add_summary pname updated_summary + + let callback_performance_checker _ _ _ tenv pname pdesc = let loc = Cfg.Procdesc.get_loc pdesc in @@ -119,10 +138,6 @@ let callback_performance_checker _ _ _ tenv pname pdesc = Checkers.ST.report_error pname pdesc calls_expensive_method loc description | Some _ when not expensive -> - let ret_annot, param_annot = attributes.ProcAttributes.method_annotation in - let updated_method_annot = - (Annotations.calls_expensive_annotation, true) :: ret_annot, param_annot in - let updated_attributes = - { attributes with ProcAttributes.method_annotation = updated_method_annot } in - AttributesTable.store_attributes updated_attributes + update_summary_attributes pname + | Some _ -> () (* Nothing to do if method already annotated with @Expensive *)