From 044ba0bca25710ce923c4d1f535513a5b12d7327 Mon Sep 17 00:00:00 2001 From: Tianhan Lu Date: Mon, 18 Nov 2024 19:42:51 -0800 Subject: [PATCH] Add logs when building higher order call graphs Summary: So that it is easier to debug. Reviewed By: arthaud Differential Revision: D65900343 fbshipit-source-id: 3951ccfac0fcf86bbd54ccc574efc7f84535534d --- source/ast/statement.ml | 4 ++++ source/ast/statement.mli | 2 ++ source/interprocedural/callGraph.ml | 33 +++++++++++++++++++++++++++- source/interprocedural/callGraph.mli | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/source/ast/statement.ml b/source/ast/statement.ml index 3aa6a4c5208..1ecce619078 100644 --- a/source/ast/statement.ml +++ b/source/ast/statement.ml @@ -633,6 +633,8 @@ and Define : sig val dump_call_graph : t -> bool + val dump_higher_order_call_graph : t -> bool + val dump_perf : t -> bool val show_json : t -> string @@ -1060,6 +1062,8 @@ end = struct let dump_call_graph define = contains_call define "pyre_dump_call_graph" + let dump_higher_order_call_graph define = contains_call define "pyre_dump_higher_order_call_graph" + let dump_perf define = contains_call define "pyre_dump_perf" let show_json define = define |> to_yojson |> Yojson.Safe.pretty_to_string diff --git a/source/ast/statement.mli b/source/ast/statement.mli index c1f02ec10b6..3ff76271ed6 100644 --- a/source/ast/statement.mli +++ b/source/ast/statement.mli @@ -309,6 +309,8 @@ and Define : sig val dump_call_graph : t -> bool + val dump_higher_order_call_graph : t -> bool + val dump_perf : t -> bool val show_json : t -> string diff --git a/source/interprocedural/callGraph.ml b/source/interprocedural/callGraph.ml index 34a08705dc8..7ac580b53bb 100644 --- a/source/interprocedural/callGraph.ml +++ b/source/interprocedural/callGraph.ml @@ -3378,6 +3378,8 @@ module HigherOrderCallGraph = struct val get_callee_model : Target.t -> t option + val debug : bool + (* Inputs and outputs. *) val mutable_define_call_graph : MutableDefineCallGraph.t ref end) = @@ -3566,7 +3568,14 @@ module HigherOrderCallGraph = struct (* Return possible callees and the new state. *) - and analyze_expression ~state ~expression:{ Node.value; location } = + and analyze_expression ~state ~expression:({ Node.value; location } as expression) = + log + ~debug:Context.debug + "Analyzing expression `%a` with state `%a`" + Expression.pp + expression + State.pp + state; match value with | Expression.Await expression -> analyze_expression ~state ~expression | BinaryOperator _ -> CallTarget.Set.bottom, state @@ -3621,6 +3630,13 @@ module HigherOrderCallGraph = struct let analyze_statement ~state ~statement = + log + ~debug:Context.debug + "Analyzing statement `%a` with state `%a`" + Statement.pp + statement + State.pp + state; match Node.value statement with | Statement.Assign { Assign.target = _; value = Some _; _ } -> state | Assign { Assign.target = _; value = None; _ } -> state @@ -3661,6 +3677,12 @@ module HigherOrderCallGraph = struct end end +let debug_higher_order_call_graph define = + Ast.Statement.Define.dump define + || Ast.Statement.Define.dump_call_graph define + || Ast.Statement.Define.dump_higher_order_call_graph define + + let higher_order_call_graph_of_define ~define_call_graph ~pyre_api @@ -3677,8 +3699,17 @@ let higher_order_call_graph_of_define let pyre_api = pyre_api let get_callee_model = get_callee_model + + let debug = debug_higher_order_call_graph define end in + log + ~debug:Context.debug + "Building higher order call graph of `%a` with initial state `%a`" + Reference.pp + (PyrePysaLogic.qualified_name_of_define ~module_name:qualifier define) + HigherOrderCallGraph.State.pp + initial_state; let module Fixpoint = HigherOrderCallGraph.MakeFixpoint (Context) in let returned_callables = Fixpoint.Fixpoint.forward ~cfg:(PyrePysaLogic.Cfg.create define) ~initial:initial_state diff --git a/source/interprocedural/callGraph.mli b/source/interprocedural/callGraph.mli index b800f8d6b9e..cb4f5f8e76b 100644 --- a/source/interprocedural/callGraph.mli +++ b/source/interprocedural/callGraph.mli @@ -389,6 +389,8 @@ module HigherOrderCallGraph : sig end end +val debug_higher_order_call_graph : Ast.Statement.Define.t -> bool + val higher_order_call_graph_of_define : define_call_graph:MutableDefineCallGraph.t -> pyre_api:PyrePysaEnvironment.ReadOnly.t ->