Skip to content

Commit

Permalink
Add logs when building higher order call graphs
Browse files Browse the repository at this point in the history
Summary: So that it is easier to debug.

Reviewed By: arthaud

Differential Revision: D65900343

fbshipit-source-id: 3951ccfac0fcf86bbd54ccc574efc7f84535534d
  • Loading branch information
Tianhan Lu authored and facebook-github-bot committed Nov 19, 2024
1 parent 2c827fa commit 044ba0b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source/ast/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/ast/statement.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion source/interprocedural/callGraph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/interprocedural/callGraph.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 044ba0b

Please sign in to comment.