Skip to content

Commit

Permalink
[textual] Improve generated ProcDesc.Node locations
Browse files Browse the repository at this point in the history
Summary:
This diff uses min instr line for node's loc. This makes node placement in a debug HTML a bit more
predictable and relevant compared to using block labels' locations which can be more detached from
the actual source code when we're dealing with translated sources (e.g. Hack->Textual).

Note that a single node can still accumulate instructions from a large number of lines (e.g. a scope
of 20 lines in the source file). Ideally, we'd improve the way we generate blocks (perhaps split
blocks into more manageable chunks) to reduce the scope of each particular node.

Reviewed By: geralt-encore

Differential Revision: D46234875

fbshipit-source-id: a895c238b3db6f8c92fc5ab36756b2dfc64cbb82
  • Loading branch information
artempyanykh authored and facebook-github-bot committed May 30, 2023
1 parent 7b3d9cb commit 7020503
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion infer/src/textual/TextualSil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,19 @@ module NodeBridge = struct
let last_loc = LocationBridge.to_sil sourcefile node.last_loc in
let last = TerminatorBridge.to_sil lang decls_env procname pdesc last_loc node.last in
let instrs = Option.value_map ~default:instrs ~f:(fun instr -> instrs @ [instr]) last in
let loc = LocationBridge.to_sil sourcefile node.label_loc in
(* Use min instr line for node's loc. This makes node placement in a debug HTML a bit more
predictable and relevant compared to using block labels' locations which can be more detached
from the actual source code when we're dealing with translated sources
(e.g. Hack->Textual). *)
let loc =
let known_instr_lines =
List.filter_map instrs ~f:(fun instr ->
match (Sil.location_of_instr instr).line with -1 -> None | other -> Some other )
in
let label_loc = LocationBridge.to_sil sourcefile node.label_loc in
let first_line = List.fold known_instr_lines ~init:label_loc.line ~f:min in
{label_loc with line= first_line}
in
let nkind = SilProcdesc.Node.Stmt_node MethodBody in
SilProcdesc.create_node pdesc loc nkind instrs

Expand Down

0 comments on commit 7020503

Please sign in to comment.